return
statement
JS Home <<
JS Reference <<
return
Value returned from a function.
Description
Specifies an expression to be returned from a function.
If no return
expression is declared the function will return undefined
.
Syntax
Signature | Description |
---|---|
return [expression]; | Specifies an expression to be returned from a function. |
Parameters
Parameter | Description |
---|---|
expression | An optional expression to be returned from the function. |
Examples
The code below gives an example of using the return
statement.
// Create a function statement that takes an argument and returns square of the argument.
function squareNumber(a) {
return a * a;
}
alert(squareNumber(9));
alert(squareNumber(13));
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 8 - Functions