return statementS2C Home « Statements « 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
expressionAn 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 the square of the argument.
 /*
function squareNumber(a) {
  return a * a;
}
alert(squareNumber(9));
alert(squareNumber(13));

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 8 - Functions

go to home page Homepage go to top of page Top