Skip to main content
The addition assignment (+=) operator evaluates the right operand, adds it to the value of the left operand, and assigns the resulting value back to the left operand. The specific operation performed—numeric addition or string concatenation—is dictated by the data types of the operands.
This operator is functionally equivalent to LeftOperand = LeftOperand + RightOperand, with the strict architectural distinction that the LeftOperand reference is evaluated only once.

Evaluation Mechanics and Type Coercion

Because JavaScript is dynamically typed, the += operator relies on the ECMAScript internal ToPrimitive algorithm and standard addition semantics to resolve the operation. 1. Numeric Addition If both operands are strictly of type Number, or if both operands are strictly of type BigInt, the operator performs standard mathematical addition. Mixing a Number operand with a BigInt operand is not permitted and will throw a TypeError.
2. String Concatenation If either the left or right operand is a String (after any necessary primitive coercion), the operator forces string concatenation. The non-string operand is implicitly coerced into a string.
3. Object to Primitive Coercion If an operand is an Object (including Array and Date), JavaScript attempts to convert it to a primitive value before applying the += operator. It does this by passing a "default" hint to the internal ToPrimitive algorithm. The resolution follows a specific hierarchy:
  1. If the object implements a [Symbol.toPrimitive]() method, that method is invoked first.
  2. If no such method exists, standard objects prioritize the valueOf() method. If valueOf() does not return a primitive, it falls back to the toString() method.
  3. Date objects exhibit the exact opposite behavior: they prioritize toString() and fall back to valueOf().
4. Boolean, Null, and Undefined Coercion When interacting with numbers (and no strings are present), JavaScript coerces true to 1, false to 0, and null to 0. undefined coerces to NaN (Not-a-Number).
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More