Increment

suggest change

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

// postfix
var a = 5;     // 5 
var b = a++;   // 5 
var c = a      // 6

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

// prefix 
var a = 5;    // 5 
var b = ++a;  // 6 
var 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 (var i = 0; i < 42; ++i)
{
  // do something awesome!
}

Notice how the prefix variant is used. This ensures that a temporarily variable isn’t needlessly created (to return the value prior to the operation).

Feedback about page:

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


Arithmetic Math:
* Increment

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
18 Arithmetic Math
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde