12.9 return statement

2010-05-23

ReturnStatement :
return [no LineTerminator here] Expression(opt) ;

A return may only occur within a function body. The return immediately stops the execution of current function. When Expression is omitted, undefined is returned, otherwise it'll be the result of Expression.

Code: (Meta Ecma)
function evaluate(return Expression(opt) ;) {
if (!Expression) return Completion('return', undefined, undefined);
var exprRef = evaluate(Expression);
return Completion('return', GetValue(exprRef), undefined);
}

Note that a most common mistake is to put the returned value of a return statement on the next line. Don't do this, it's explicitly forbidden in the specification and the Automatic Semi-colon Insertion will come for you and eat you alive.