Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Arrays Intro
Making Arrays
Array Builder Kata
Array Elements
Human Names Kata
Array Length
Longest Array Kata
Looping Over Arrays
Highest Number Kata
Word Hunter Kata
Array Average Kata
Min-Max Kata
Adding Elements
Number Range Kata
Removing Elements
Arrays of Objects
Biggest Animal Kata
Arrays of Arrays
Taboo Words Kata
Going Further
Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Arrays Intro
Making Arrays
Array Builder Kata
Array Elements
Human Names Kata
Array Length
Longest Array Kata
Looping Over Arrays
Highest Number Kata
Word Hunter Kata
Array Average Kata
Min-Max Kata
Adding Elements
Number Range Kata
Removing Elements
Arrays of Objects
Biggest Animal Kata
Arrays of Arrays
Taboo Words Kata
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