The --
operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.
The --
operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.
The --
operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt decrement if the operand becomes a BigInt; otherwise, it performs number decrement.
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.
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
Decrement |
2 | 12 | 1 | 3 | 4 | 18 | 4 | 10.1 | 3.2 | 1.0 | 4.4 | 1.0 | 0.10.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Decrement