Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Subtraction assignment (-=)

The -= operator subtracts the right operand from the current value of the left operand and stores the result in the same location. It performs numeric conversion, and the whole expression returns the assigned value.

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

target -= expression

The -= operator combines subtraction with assignment. For a simple variable, x -= y works like x = x - y, but the expression identifying the left operand is evaluated only once. This matters when accessing a property or an array element with side effects.

First, the storage location is determined and its value is read; then the right operand is evaluated. Numeric conversion is followed by subtraction and storage. The value of the whole expression is the subtraction result.

After conversion, the operands must both be Number values or both be BigInt values; mixing these types throws TypeError. Numeric text such as "12" can become a Number. Unlike +=, the -= operator does not concatenate strings.

The left operand must be a valid assignment target. Attempting to change a variable declared with const throws TypeError. In the example, remaining becomes the number 7, and result receives the same value.

Examples

let remaining = "12";
const result = (remaining -= 5);
console.log(remaining);
console.log(result);
console.log(typeof remaining);

Result

7
7
number

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources