ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

14.10 The return Statement

Syntax

ReturnStatement[Yield, Await] : return ; return [no LineTerminator here] Expression[+In, ?Yield, ?Await] ; Note

A return statement causes a function to cease execution and, in most cases, returns a value to the caller. If Expression is omitted, the return value is undefined. Otherwise, the return value is the value of Expression. A return statement may not actually return a value to the caller depending on surrounding context. For example, in a try block, a return statement's Completion Record may be replaced with another Completion Record during evaluation of the finally block.

14.10.1 Runtime Semantics: Evaluation

ReturnStatement : return ;
  1. Return Completion Record { [[Type]]: return, [[Value]]: undefined, [[Target]]: empty }.
ReturnStatement : return Expression ;
  1. Let exprRef be ? Evaluation of Expression.
  2. Let exprValue be ? GetValue(exprRef).
  3. If GetGeneratorKind() is async, set exprValue to ? Await(exprValue).
  4. Return Completion Record { [[Type]]: return, [[Value]]: exprValue, [[Target]]: empty }.