JavaScript Introduction | Operators | Increment and Decrement Operators

Increment and Decrement Operators

Increment and decrement operators are used to increase or decrease an operand by 1.
These operators are unary operators with only one operand.

The order and result of the operation depend on which side of the operand the operator is placed.

Increment/decrement operator Description
++x Increases the operand value by 1 first, then performs the operation.
x++ Performs the operation first, then increases the operand value by 1.
–x Decreases the operand value by 1 first, then performs the operation.
x– Performs the operation first, then decreases the operand value by 1.
var x = 10, y = 10;
document.write((++x - 3) + "<br>"); // First increases x by 1, then subtracts 3.
document.write(x + "<br>");         // 11
document.write((y++ - 3) + "<br>"); // First subtracts 3 from y, then increases y by 1.
document.write(y);                  // 11