JavaScript returnStatement
JavaScript Statement Reference
Examples
Return the value of PI:
Output:
Try it Yourself »
This article contains more examples at the bottom.
Definition and Usage
The return statement stops the execution of a function and returns the value of the function.
Please read our JavaScript tutorial to learn more about functions. First, we can start by understandingJavaScript FunctionsandJavaScript Scope. For more detailed content, you can viewFunction Definitions, Parameters, InvocationandClosures。
Browser Support
| Statement | |||||
|---|---|---|---|---|---|
| return | Yes | Yes | Yes | Yes | Yes |
Syntax
return [[expression]];
Return the value of expression. If omitted, i.e.return;then undefined is returned.
The following return statements all terminate the execution of the function:
return; return true; return false; return x; return x + y / 3;
Parameter Values
| Parameter | Description |
|---|---|
| value | Optional. Specifies the returned function value. If omitted, will returnundefined |
Technical Details
| JavaScript Version: | 1.0 |
|---|

More Examples
Example
Calculate the product of two numbers and return the result:
function myFunction(a, b) {
return a * b; // The function returns the product of a and b
}
Try it Yourself »
Return a Function
return function calc(x) { return x * 42};
}
var answer = magic();
answer(1337); // 56154
Related Pages
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
JavaScript Statements Reference Other Extensions