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.

Javascript




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.

Javascript




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:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button