
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return 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>
Advertisements