Increment Operator in JavaScript



Increment Operator

In JavaScript, Arithmetic increment operator takes a variable as operand, increments the value in the variable by one.

++ symbol is used for arithmetic increment operator.

Based on whether the incremented value is reflected in the variable during post executing the statement, or while executing the statement, there are two types of increment operations: post-increment, and pre-increment.

a++  //post-increment
++a  //pre-increment 

Examples

1. Increment value in a by one.

var a = 6;
a++;
console.log(a);

2. Post-increment value in a by one.

var a = 6;
console.log(a++);
//6
console.log(a);
//7

3. Pre-increment value in a by one.

var a = 6;
console.log(++a);
//7
console.log(a);
//7