Essential JavaScript

Add and Subtract

We have already seen how JavaScript can do math.

We can add and subtract any number of numbers together:

1 + 2 + 17 - 9 + 5 - 4

And we get 12 as a result.

Negative Numbers

What happens when you subtract 2 from 1?

You get -1, of course. JavaScript knows this. JavaScript understands negative numbers and is happy to work with them as well.

Try running: 1 - 2

Try running: -1 + 2

Try running: -2 + -3

Try running: 1 - -2


Learning Goals

Code Editor