Decrement (--)

The decrement (--) operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.

Try it

Syntax

x--
--x

Description

If used postfix, with operator after operand (for example, x--), the decrement operator decrements and returns the value before decrementing.

If used prefix, with operator before operand (for example, --x), the decrement operator decrements and returns the value after decrementing.

The decrement operator can only be applied on operands that are references (variables and object properties; i.e. valid assignment targets). --x itself evaluates to a value, not a reference, so you cannot chain multiple decrement operators together.

--(--x); // SyntaxError: Invalid left-hand side expression in prefix operation

Examples

Postfix decrement

let x = 3;
const y = x--;

// x = 2
// y = 3

Prefix decrement

let x = 3;
const y = --x;

// x = 2
// y = 2

Specifications

Specification
ECMAScript Language Specification
# sec-postfix-decrement-operator

Browser compatibility

BCD tables only load in the browser

See also