Open In App

Subtraction(-) Arithmetic Operator in JavaScript

JavaSscript arithmetic subtraction operator is used to find the difference between operators after subtracting them. Depending on the nature of the two operands, the subtraction operator performs either number subtraction or BigInt subtraction after converting both operands to numeric values.

Syntax:

a-b

Return Type: It returns a number after subtracting the operators.

Example 1: In this example, we will use the subtraction operator on Numbers and Strings.




console.log(200-100);
console.log("10"-2);
console.log("Hello" - 3);

Output: The numbers in the string are converted to the corresponding numbers whereas words in the string are converted to NaN.

100
8
NaN

Example 2: In this example, we will perform a subtraction operation on the BigInt data type.




console.log(200n-100n);
console.log(200n-100);

Output: When we try to subtract the BigInt from a number we get an error.

JavaScript Arithmetic Subtraction(-) Operator

Supported Browser:

We have a complete list of Javascript Arithmetic operators, to check those please go through this JavaScript Arithmetic Operators article.

Article Tags :