Increment

suggest change

The Increment operator (++) increments its operand by one.

// postfix
let a = 5;     // 5
const b = a++;   // 5
const c = a      // 6

In this case, a is incremented after setting b. So, b will be 5, and c will be 6.

// prefix
let a = 5;    // 5
const b = ++a;  // 6
const c = a;    // 6

In this case, a is incremented before setting b. So, b will be 6, and c will be 6.

The increment and decrement operators are commonly used in for loops, for example:

for (let i = 0; i < 42; ++i)
{
  // do something awesome!
}

The loop ignores the value of the update expression, so i++ and ++i do the same work. Prefix does not avoid a temporary or make the loop faster.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents