Skip to main content
The subtraction assignment operator (-=) subtracts the value of the right operand from the variable specified by the left operand and assigns the computed result back to that variable.
Semantically, x -= y is equivalent to x = x - y, with the technical distinction that the LeftOperand is evaluated only once. This distinction is relevant when the left operand involves complex property accessors (getters/setters) or function calls.

Execution Mechanics and Type Coercion

Unlike the addition assignment operator (+=), which is overloaded to handle both numeric addition and string concatenation, the -= operator strictly performs mathematical subtraction. Consequently, it forces the JavaScript engine to apply the ToNumeric abstract operation to both operands.
  1. L-value Resolution: The engine verifies that the LeftOperand is a valid assignment target (a mutable variable or property).
  2. Value Evaluation: The current value of the LeftOperand is retrieved, followed by the evaluation of the RightOperand.
  3. Implicit Coercion: Both values are coerced to primitives, and then to Numbers (or BigInts).
  4. Computation & Assignment: The subtraction is performed, and the resulting value is written to the memory space of the LeftOperand.

Coercion Behaviors

Because -= forces numeric context, it yields specific results based on the types of the operands:

BigInt Constraints

The -= operator supports BigInt operands, but strict type matching is enforced. Mixing BigInt and Number types without explicit conversion will throw a TypeError.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More