JavaScript Arithmetic (Math) Subtraction (-)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The subtraction operator (-) subtracts numbers.


var a = 9;
var b = 3;
var c = a - b;

c will now be 6

If a string or boolean is provided in place of a number value, it gets converted to a number before the difference is calculated (0 for false, 1 for true):

"5" - 1;     // 4
7 - "3";     // 4
"5" - true;  // 4

If the string value cannot be converted into a Number, the result will be NaN:

"foo" - 1;      // NaN
100 - "bar";    // NaN


Got any JavaScript Question?