JavaScript Statements Reference
Return the value of PI:
The result will be:
More "Try it Yourself" examples below.
The return statement stops the execution of a function and returns a value from that function.
Read our JavaScript Tutorial to learn all you need to know about functions. Start with the introduction chapter about JavaScript Functions and JavaScript Scope. For more detailed information, see our Function Section on Function Definitions, Parameters, Invocation and Closures.
Statement | |||||
---|---|---|---|---|---|
return | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
value | Optional. Specifies the value to be returned to the function caller. If omitted, it returns undefined |
JavaScript Version: | 1.0 |
---|
Calculate the product of two numbers, and return the result:
The result of x will be:
JavaScript Tutorial: JavaScript Functions
JavaScript Tutorial: JavaScript Scope
JavaScript Tutorial: JavaScript Function Definitions
JavaScript Tutorial: JavaScript Function Parameters
JavaScript Tutorial: JavaScript Function Invocation
JavaScript Tutorial: JavaScript Function Closures
JavaScript Reference: JavaScript function Statement