CKTIS / JavaScript
Addition assignment (+=)
The += operator performs numeric addition or string concatenation, then attempts to write the result to the assignment target, which it evaluates only once. If the write does not throw, the expression yields the computed result even if the write is ignored.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
target += expressiontarget += expression reads the target's current value, evaluates the right operand, applies the rules of +, and attempts to write the result to that same target. If the write does not throw, the entire expression evaluates to the computed result. In non-strict code, a write to a non-writable property can be silently ignored: the property remains unchanged, but the expression still yields the computed result. In strict mode, such a write throws TypeError.
For a simple variable, it resembles target = target + expression, but the target is evaluated only once. This matters with properties, indexes, and side effects. The left side must be a valid assignment target; assigning to a const binding throws TypeError.
Operands are first converted to primitive values. If at least one of those values is a string, the operator attempts string concatenation. Pairing a string with a Symbol throws TypeError during implicit conversion of the symbol to a string. If neither value is a string, the operator attempts to convert both values for numeric addition. Converting a Symbol in this case throws TypeError. Mixing Number and BigInt in numeric addition also throws TypeError. Consequently, total += "3" can turn a number into a string. Objects can execute custom code during conversion.
Examples
let total = 7;
const result = (total += 5);
console.log(total, result);
total += "3";
console.log(total, typeof total);
let count = 7n;
count += 5n;
console.log(String(count));Result
12 12 123 string 12
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.