TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
+= (addition assignment) operator evaluates the addition or string concatenation of the right operand and the current value of the left operand, subsequently assigning the evaluated result back to the left operand.
leftOperand = leftOperand + rightOperand, the += operator evaluates the leftOperand exactly once. This distinction is critical when the left operand contains side effects (such as an incrementing index or a getter method). In an expression like arr[i++] += 5, the index i is evaluated and incremented only once, whereas the expanded form arr[i++] = arr[i++] + 5 would evaluate the increment operation twice, yielding a completely different result.
Type Resolution and Behavior
In TypeScript, the behavior of the+= operator is dictated by the types of the operands. The TypeScript compiler (tsc) enforces strict type checking during this operation to prevent implicit type coercion anomalies common in standard JavaScript.
- Numeric Addition: If both operands are strictly of type
number, or if both operands are strictly of typebigint, the operator performs standard mathematical addition. TypeScript strictly prohibits mixingnumberandbigintin the same operation. - String Concatenation: If either the left or right operand is of type
string, the operator performs string concatenation. - Type Assignability: TypeScript verifies that the return type of the evaluated expression is assignable to the declared type of the
leftOperand. If it is not, the compiler emits a type error.
Syntax Visualization
Evaluation Semantics:Master TypeScript with Deep Grasping Methodology!Learn More





