The increment operator (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
++) is a unary mutator operator that adds one (1) to its operand and evaluates to a numeric value. It requires an l-value (such as a variable, array element, or object property) as its operand. If the operand is not already a numeric type, the operator applies the internal ToNumeric abstract operation to coerce it into a Number or BigInt before performing the addition.
The operator has two distinct syntactic forms that dictate the order of evaluation and mutation: postfix and prefix.
Postfix Increment (x++)
In the postfix position, the operator evaluates and returns the current value of the operand before the increment operation occurs. The mutation happens in memory, but the expression itself resolves to the unmutated value.
Prefix Increment (++x)
In the prefix position, the operator increments the operand in memory first, and then the expression evaluates to the newly incremented value.
Implicit Type Coercion and ToNumeric
Unlike the binary addition operator (+), which can perform string concatenation, the ++ operator strictly performs mathematical addition. By applying the ToNumeric abstract operation, the operator handles different data types as follows:
- BigInt: If the operand is a
BigInt, it is incremented by1n. It is not coerced to aNumber, and its type remains"bigint". - Valid Coercible Types: If the operand is a numeric String, Boolean, or Null, it is coerced into a
Numberand incremented by1. Because JavaScript variables are dynamically typed, this simply reassigns the variable to a new value of typeNumber. - Invalid Numeric Strings and
undefined: If the operand isundefinedor a string that cannot be parsed into a valid number (e.g.,"hello"), theToNumericoperation evaluates toNaN. IncrementingNaNresults inNaN. - Symbols: Symbols cannot be coerced into numeric values. Applying the increment operator to a
Symbolwill throw aTypeError.
Invalid Operands
Because the++ operator must mutate its operand, it cannot be applied to r-values such as literals or the evaluated results of expressions. Attempting to do so results in a SyntaxError during the parsing phase.
Master JavaScript with Deep Grasping Methodology!Learn More





