411 REFERENCE · Wikibooks
JavaScript/Reserved words/return
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
JavaScript public short Reserved words 0
The return keyword
The return keyword ends the function, specifying the value to be returned. Without this expression, undefined is returned.
Please note that adding a carriage return inbetween the statement and the value results in splitting it into two separate statements, returning with undefined. This is because of the automatic semicolon insertion (ASI).
Examples
Example 1
function getValue() {
return value;
}
The getter getValue returns with value.
Example 2
function getName() {
return // <<<< == "return undefined;"
name; // <<<< unreachable code!
}
The getter getName returns with undefined.
JavaScript public short Reserved words 0