YouTip LogoYouTip

Jsref Return

# JavaScript return Statement [![Image 4: JavaScript Statement Reference](#) JavaScript Statement Reference](#) ## Example Return the value of PI: function myFunction(){return Math.PI; } Output: 3.141592653589793 [Try it Yourself Β»](#) More examples are included at the bottom of this page. * * * ## Definition and Usage The return statement terminates function execution and returns a value from the function. Please read our JavaScript tutorial to learn more about functions. First, we can learn about (#) and (#). For more detailed content, see (#), (#), (#), and (#). * * * ## Browser Support | Statement | | | | | | | --- | --- | --- | --- | --- | --- | | return | Yes | Yes | Yes | Yes | Yes | * * * ## Syntax return []; Returns the value of expression. If omitted, i.e., return; then it returns undefined. The following return statements will 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 value to be returned from the function. If omitted, it returns **undefined** | ## Technical Details | JavaScript Version: | 1.0 | | --- | * * * ![Image 5: Example](#) ## More Examples ## Example Calculate the product of two numbers and return the result: var x = myFunction(4, 3); // Call the function, assign the return value to variable x function myFunction(a, b) { return a * b; // Function returns the product of a and b } The output of _x_ will be: 12 [Try it Yourself Β»](#) ## Return a Function function magic(x){ return function calc(x){return x *42}; } var answer = magic(); answer(1337);// 56154 * * * ## Related Pages JavaScript Tutorial: (#) JavaScript Tutorial: (#) JavaScript Tutorial: (#) JavaScript Tutorial: (#) JavaScript Tutorial: (#) JavaScript Tutorial: (#) JavaScript Reference: [JavaS
← C Function LongjmpC Function Fabs β†’