Essential JavaScript

Going Further

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

  • I can add numbers in JavaScript

  • I can subtract numbers in JavaScript

  • I can work with negative numbers in JavaScript

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines