- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it required to have a return a value from a JavaScript function?
A JavaScript function can have an optional return statement i.e. it’s optional to return a value. This statement should be the last statement in a function.
For example, you can pass two numbers in a function and then you can expect the function to return their multiplication to your calling program.
Example
Try the following example. It defines a function that takes two parameters and concatenates them before returning the resultant in the calling program.
<html> <head> <script type = "text/javascript"> function concatenate(first, last){ var full; full = first + last; return full; } function secondFunction(){ var result; result = concatenate('John', 'Doe'); document.write (result ); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "secondFunction()" value = "Call Function"> </form> <p>Use different parameters inside the function and then try...</p> </body> </html>
- Related Articles
- How to return a value from a JavaScript function?
- How to return a string from a JavaScript function?
- How to return an object from a JavaScript function?
- How to get the return value from a function in a class in Python?
- MongoDB function to return a specific data/value?
- How to have a function return a figure in Python (using Matplotlib)?
- Is it possible to have a function-based index in MySQL?
- Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL
- How to return a json object from a Python function?
- C++ Program to create a function with arguments and a return value
- How to return a local array from a C/C++ function
- How to return local array from a C++ function?
- Is it possible to return a list of specific values from a MongoDB query?
- Can we have a return statement in a JavaScript switch statement?
- How to return variable value from jQuery event function?

Advertisements