--- title: Subtraction assignment (-=) slug: Web/JavaScript/Reference/Operators/Subtraction_assignment translation_of: Web/JavaScript/Reference/Operators/Subtraction_assignment ---
{{jsSidebar("Operators")}}

The subtraction assignment operator (-=) subtracts the value of the right operand from a variable and assigns the result to the variable.

{{EmbedInteractiveExample("pages/js/expressions-subtraction-assignment.html")}}

语法

Operator: x -= y
Meaning:  x  = x - y

Examples

Using subtraction assignment

// Assuming the following variable
//  bar = 5

bar -= 2     // 3
bar -= 'foo' // NaN

Specifications

Specification
{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}

Browser compatibility

{{Compat("javascript.operators.subtraction_assignment")}}

See also