Exits from the current function and returns a value from that function.
Syntaxreturn [ ( ][ expression ][ ) ];
Examples
The following example illustrates the use of the return statement.
function myfunction(arg1, arg2){
var r;
r = arg1 * arg2;
return(r);
}
The following example illustrates the use of the return statement to return a function.
function doWork() {
return function calculate(y) { return y + 1; };
}
var func = doWork();
var x = func(5);
document.write(x);
Remarks
The optional expression argument is the value to be returned from the function. If omitted, the function does not return a value.
You use the return statement to stop execution of a function and return the value of expression. If expression is omitted, or no return statement is executed from within the function, the expression that called the current function is assigned the value undefined.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4