ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

13.13 Binary Logical Operators

Syntax

LogicalANDExpression[In, Yield, Await] : BitwiseORExpression[?In, ?Yield, ?Await] LogicalANDExpression[?In, ?Yield, ?Await] && BitwiseORExpression[?In, ?Yield, ?Await] LogicalORExpression[In, Yield, Await] : LogicalANDExpression[?In, ?Yield, ?Await] LogicalORExpression[?In, ?Yield, ?Await] || LogicalANDExpression[?In, ?Yield, ?Await] CoalesceExpression[In, Yield, Await] : CoalesceExpressionHead[?In, ?Yield, ?Await] ?? BitwiseORExpression[?In, ?Yield, ?Await] CoalesceExpressionHead[In, Yield, Await] : CoalesceExpression[?In, ?Yield, ?Await] BitwiseORExpression[?In, ?Yield, ?Await] ShortCircuitExpression[In, Yield, Await] : LogicalORExpression[?In, ?Yield, ?Await] CoalesceExpression[?In, ?Yield, ?Await] Note

The value produced by a && or || operator is not necessarily of type Boolean. The value produced will always be the value of one of the two operand expressions.

13.13.1 Runtime Semantics: Evaluation

LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. Let lref be ? Evaluation of LogicalANDExpression.
  2. Let lval be ? GetValue(lref).
  3. Let lbool be ToBoolean(lval).
  4. If lbool is false, return lval.
  5. Let rref be ? Evaluation of BitwiseORExpression.
  6. Return ? GetValue(rref).
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. Let lref be ? Evaluation of LogicalORExpression.
  2. Let lval be ? GetValue(lref).
  3. Let lbool be ToBoolean(lval).
  4. If lbool is true, return lval.
  5. Let rref be ? Evaluation of LogicalANDExpression.
  6. Return ? GetValue(rref).
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. Let lref be ? Evaluation of CoalesceExpressionHead.
  2. Let lval be ? GetValue(lref).
  3. If lval is either undefined or null, then
    1. Let rref be ? Evaluation of BitwiseORExpression.
    2. Return ? GetValue(rref).
  4. Else,
    1. Return lval.