Open In App

Decrement(–) Arithmetic Operator in JavaScript

JavaScript decrement operator is used to decrease the value of the variable by one. The value returned from the operand depends on whether the decrement operator was on the left(prefix decrement) or right(postfix decrement). If the operator is used before the operand then the value is decreased by one and then returned but if the operator is after the operand then the value is first returned and then decremented. 

The decrement operator can only be used on references that is the operator can only be applied to variable and object properties. Also, the decrement operator cannot be chained



Syntax:

--a
OR
a--

 



Example 1: In this example, we will see the value returned when the decrement operator is applied after the operand(postfix decrement).




let x = 10;
console.log(x--);
console.log(x);

Output: We can observe that first the value is returned and then decremented.

10
9

Example 2: In this example, we will see the values returned when the operator is applied before the operand(prefix decrement).




let x = 10;
console.log(--x);
console.log(x);

Output: Here the value is first decremented and then returned.

9
9

Supported Browsers:

We have a complete list of Javascript Arithmetic operators, to check those please go through this JavaScript Arithmetic Operators article.

Article Tags :