Sitemap

Subtraction JavaScript

Apr 12, 2022

--

Arithmetic Operators — Subtraction

Math involves both, numbers & operations. Operations tell us what to do with the numbers.

Press enter or click to view image in full size
Photo by Antoine Dautry on Unsplash

Subtract a number from another with JavaScript

What is subtraction?

Get Firdavsi Web Dev’s stories in your inbox

Join Medium for free to get updates from this writer.

To subtract numbers means to take away a number from another.

JavaScript uses the minus sign (-) as subtraction operator when placed in between two numbers. Let’s see it in code.

const difference = 7 - 5;
console.log(difference);

Here everything to the right side of equal sign is evaluated first or it first does the math 7–5 = 2

Then the result or difference 2 is being stored to the variable difference.

That’s why when you log the variable difference to the console, you’ll get the result which is 2 but not 7–5

--

--

Firdavsi Web Dev
Firdavsi Web Dev

Written by Firdavsi Web Dev

Hey there! I’m Firdavsi, a Math Lover. Obsessed with Computer Programming, Design and Science. Learn Web Development at https://w7school.com