Open In App

Subtraction Assignment( -=) Operator in Javascript

Last Updated : 29 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Javascript




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.

Javascript




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


Output:

NaN

Supported browser:

  • Google Chrome
  • Mozilla Firefox
  • Safari
  • Internet Explorer

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads