Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Increment and decrement (++ --)

Increases or decreases a variable by one.

Available since: ES1

Syntax

x++ / ++x / x-- / --x

Examples

Increasing and decreasing:

let count = 5;
count++;
count++;
count--;
 
console.log(count);

Output:

6

The postfix and prefix forms return different values:

let a = 1;
let b = 1;
 
console.log(a++);
console.log(++b);
console.log(a, b);

Output:

1
2
2 2

Notes

To avoid confusion, use ++ on its own line, not inside other expressions. For steps other than one use x += 2. It does not work with const: declare the variable with let.

See also

  • Remainder (%) — The remainder of a division.
  • let — Declares a variable whose value can change.

In the tutorial

  • Operators — JavaScript arithmetic operators, the remainder, operator precedence, compound assignment, ++ and --.

Thanks for reading!

Donate to the site — we work hard for you.