Increment (++)

The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.

Try it

Syntax

x++
++x

Description

If used postfix, with operator after operand (for example, x++), the increment operator increments and returns the value before incrementing.

If used prefix, with operator before operand (for example, ++x), the increment operator increments and returns the value after incrementing.

The increment operator can only be applied on operands that are references (variables and object properties; i.e. valid assignment targets). ++x itself evaluates to a value, not a reference, so you cannot chain multiple increment operators together.

++(++x); // SyntaxError: Invalid left-hand side expression in prefix operation

Examples

Postfix increment

let x = 3;
const y = x++;

// x = 4
// y = 3

Prefix increment

let x = 3;
const y = ++x;

// x = 4
// y = 4

Specifications

Specification
ECMAScript Language Specification
# sec-postfix-increment-operator

Browser compatibility

BCD tables only load in the browser

See also