JavaScript ++ Increment Operator
The increment operator (++) adds one to a variable. Placed after the variable it returns the old value; placed before, it returns the new value.
Description
The increment operator ++ adds 1 to its operand and stores the result. In postfix form, x++, the expression returns the value before incrementing; in prefix form, ++x, it returns the value after. When used on its own line, as in a for loop, there's no difference.
The operand must be something that can be assigned to, such as a variable or property; 5++ is a syntax error. Many style guides prefer x += 1 because it's clearer.
Because x++ both changes a variable and returns a value, using it inside larger expressions, such as arr[i++] = value, packs two actions into one line and can be easy to misread. It's clearest on a line of its own or in a for loop's update. Applied to a string, the value is converted to a number first, so let s = '5'; s++ leaves s as the number 6. It also works with BigInts.
Properties
- Operator
++- Category
- Arithmetic
- Precedence
- 15 (1 is lowest, 18 is highest)
- Associativity
- n/a
Syntax
x++
++xExample
Browser Support
The following information will show you the current browser support for the ++ operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





