JavaScript -- Decrement Operator
The decrement operator (--) subtracts one from a variable. Like ++, it returns the old value in postfix form and the new value in prefix form.
Description
The decrement operator -- subtracts 1 from its operand and stores the result. x-- returns the original value, and --x returns the new value.
Like increment, the postfix and prefix forms only differ in the value the expression returns, not in their effect on the variable. while (count--) is a compact countdown loop: it tests the old value, so it runs once for each number down to 1 and stops when the value it checks is 0. A non-numeric value is converted to a number first, and undefined-- gives NaN.
The operand must be assignable, so --5 or (a + b)-- are syntax errors. Writing x -= 1 instead says the same thing more explicitly, and some style guides, and linter rules like ESLint's no-plusplus, prefer it for that reason.
Properties
- Operator
--- Category
- Arithmetic
- Precedence
- 15 (1 is lowest, 18 is highest)
- Associativity
- n/a
Syntax
x--
--xExample
Browser Support
The following information will show you the current browser support for the -- operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





