Latest web development tutorials

JavaScript return statement

JavaScript Statements Reference Manual JavaScript Statements Reference Manual

Examples

Returns the value of PI:

function myFunction () {
return Math.PI;
}

Output:

3.141592653589793

try it"

Bottom of this article contains more examples.


Definition and Usage

return statement terminates execution of the function and the function's return value.

Please read our JavaScript tutorials to learn more about the function of the content. First, we can first understand JavaScript function and JavaScript scope . You can view more detailed data about the function definition , parameters , call and closures .


Browser Support

Statements
return Yes Yes Yes Yes Yes


grammar

return value;

Parameter Value

parameter description
value Optional. Returns only the specified function. If omitted, returns undefined

technical details

JavaScript version: 1.0


Examples

More examples

Examples

Calculate the product of two numbers and returns the result:

var x = myFunction (4, 3); // call the function will return the value assigned to the variable x

function myFunction (a, b) {
return a * b; // function returns the product of a and b
}
x The output is:
12

try it"


Related Pages

JavaScript Tutorials: JavaScript function

JavaScript Tutorials: JavaScript Scope

JavaScript Tutorials: JavaScript function definition

JavaScript Tutorials: JavaScript function parameters

JavaScript Tutorials: JavaScript function call

JavaScript Tutorials: JavaScript function closures

JavaScript Reference Manual: JavaScript function statements


JavaScript Statements Reference Manual JavaScript Statements Reference Manual