CKTIS / JavaScript
Decrement operator (--)
The -- operator subtracts one and writes the result back to its operand. The x-- form returns the previous numeric value, while --x returns the new value. Both support Number and BigInt.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
x--
--xThe -- operator reads its operand, converts its value to a numeric type, subtracts one, and writes the result back. It subtracts 1 for Number and 1n for BigInt.
The postfix form x-- returns the numeric value before the change; the prefix form --x returns the new value. Both write back during evaluation of the expression, not on the next line. As standalone statements, they have the same effect.
The operand must be a valid assignment target, such as a variable or an object property. 3-- is a syntax error, and attempting to update a const variable throws TypeError. A line break is not allowed between the operand and postfix --.
Conversion can change the type: if x contains "3", after x-- it contains the number 2, and the expression returns the number 3. Number precision limits apply: subtracting one does not always change a very large value. Avoid updating the same variable multiple times within one expression.
Examples
let count = 3;
const previous = count--;
console.log(previous, count);
const current = --count;
console.log(current, count);
let big = 3n;
big--;
console.log(String(big));Result
3 2 1 1 2
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.