ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

13.4 Update Expressions

Syntax

UpdateExpression[Yield, Await] : LeftHandSideExpression[?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] [no LineTerminator here] ++ LeftHandSideExpression[?Yield, ?Await] [no LineTerminator here] -- ++ UnaryExpression[?Yield, ?Await] -- UnaryExpression[?Yield, ?Await]

13.4.1 Static Semantics: Early Errors

UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- UpdateExpression : ++ UnaryExpression -- UnaryExpression

13.4.2 Postfix Increment Operator

13.4.2.1 Runtime Semantics: Evaluation

UpdateExpression : LeftHandSideExpression ++
  1. Let lhs be ? Evaluation of LeftHandSideExpression.
  2. Let oldValue be ? ToNumeric(? GetValue(lhs)).
  3. If oldValue is a Number, then
    1. Let newValue be Number::add(oldValue, 1𝔽).
  4. Else,
    1. Assert: oldValue is a BigInt.
    2. Let newValue be BigInt::add(oldValue, 1).
  5. Perform ? PutValue(lhs, newValue).
  6. Return oldValue.

13.4.3 Postfix Decrement Operator

13.4.3.1 Runtime Semantics: Evaluation

UpdateExpression : LeftHandSideExpression --
  1. Let lhs be ? Evaluation of LeftHandSideExpression.
  2. Let oldValue be ? ToNumeric(? GetValue(lhs)).
  3. If oldValue is a Number, then
    1. Let newValue be Number::subtract(oldValue, 1𝔽).
  4. Else,
    1. Assert: oldValue is a BigInt.
    2. Let newValue be BigInt::subtract(oldValue, 1).
  5. Perform ? PutValue(lhs, newValue).
  6. Return oldValue.

13.4.4 Prefix Increment Operator

13.4.4.1 Runtime Semantics: Evaluation

UpdateExpression : ++ UnaryExpression
  1. Let expr be ? Evaluation of UnaryExpression.
  2. Let oldValue be ? ToNumeric(? GetValue(expr)).
  3. If oldValue is a Number, then
    1. Let newValue be Number::add(oldValue, 1𝔽).
  4. Else,
    1. Assert: oldValue is a BigInt.
    2. Let newValue be BigInt::add(oldValue, 1).
  5. Perform ? PutValue(expr, newValue).
  6. Return newValue.

13.4.5 Prefix Decrement Operator

13.4.5.1 Runtime Semantics: Evaluation

UpdateExpression : -- UnaryExpression
  1. Let expr be ? Evaluation of UnaryExpression.
  2. Let oldValue be ? ToNumeric(? GetValue(expr)).
  3. If oldValue is a Number, then
    1. Let newValue be Number::subtract(oldValue, 1𝔽).
  4. Else,
    1. Assert: oldValue is a BigInt.
    2. Let newValue be BigInt::subtract(oldValue, 1).
  5. Perform ? PutValue(expr, newValue).
  6. Return newValue.