JavaScript Subtraction Assignment Operator



Subtraction Assignment

In JavaScript, Subtraction assignment operator takes two operands, subtracts the value in left operand with that of the right operand and assigns the result back to the left operand.

Syntax

-= symbol is used for subtraction assignment operator.

a -= 5  //equivalent to a = a -+ 5
a -= b  //equivalent to a = a - b

Examples

1. Subtraction assign a with 5.

var a = 4;
a -= 5;
console.log(a);

2. Subtract b from a and assign the result back to a.

var b = 7;
var a = 4;
a -= b;
console.log(a);