Deep Space

Arithmetic Operators — Subtraction

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

Photo by Antoine Dautry on Unsplash

Subtract a number from another with JavaScript

What is subtraction?

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

--

--

Deep Space

Deep Space

I’m Lia Sue Kim, a Math Lover. Obsessed with Computer Programming, Design and Science. Buy me a Coffee: buymeacoffee.com/DeepSpaceX