Open In App

Subtraction Assignment( -=) Operator in Javascript

The Subtraction Assignment Operator( -=) is used to subtract a value from a variable. This operator subtracts the value of the right operand from a variable and assigns the result to the variable, in other words, allows us to decrease the left variable from the right value.

Syntax:



a -= b 

We will now see some examples of the javascript Subtraction Assignment (-=).

Example 1: In this example, we will use the Subtraction Assignment Operator on numerical values.






let number = 9;
number -= 5;
console.log(number);

Output:

4

Example 2: In this example, we will be subtracting a string with a number using the subtraction assignment operator.




let number = 10;
  
let string = "num"
console.log(number -= string);

Output:

NaN

Supported browser:

We have a complete list of Javascript Assignment operators, to check those please go through the Javascript Assignment Operators.

Article Tags :