01 / 05
Write a sum and it gets worked out
The basics of syntax
INPUT · Slides
01 / 05
Put a sum inside the brackets of console.log() and the answer is what shows up.
When JS spots a sum, it works it out first and shows the result.
console.log(3 + 5);Result
8
02 / 05
The symbols are a little different from the ones you know, so learn them now.
+-* (an asterisk, not ×)* is the symbol on your keyboard. The × from your maths book will not work.
console.log(10 + 4);console.log(10 - 4);console.log(10 * 4);Result
14 6 40
03 / 05
You can chain the symbols up. Multiplication happens before addition, exactly as it does on paper.
When you want a different order, wrap that part in ( ).
console.log(2 + 3 * 4);console.log((2 + 3) * 4);Result
14 20
04 / 05
A space either side of a symbol changes nothing. JS does not mind.
But it reads better with them in, so this course will always put them in.
You spend longer reading code than writing it. It is worth the effort.
console.log(3+5);console.log(3 + 5);Result
8 8
05 / 05
Right now you are typing the numbers straight in. From the next lesson you can give a value a name and do maths with that instead.
You will be able to write total = price * count — a sum you can actually read. Maths is the floor everything else stands on, so get comfortable with the symbols here.