Numbers, Words, and Other Things in JavaScript

We know that we can change things, but how can each kind of variable change in JavaScript? Let’s take them one at a time.

Numbers

You can use standard math symbols to add and subtract numbers in JavaScript. Try the following in the JavaScript console, pressing Enter after each math problem.

​ 5 + 2
​ 10 - 9.5
​ 23 - 46
​ 84 + -42

You should get back the following answers (the answer is shown in the comments below the math problem).

​ 5 + 2
​ ​// 7​
​ 
​ 10 - 9.5
​ ​// 0.5​
​ 
​ 23 - 46
​ ​// -23​
​ 
​ 84 + -42
​ ​// 42​

So it even works with negative numbers. Remember this, because negative numbers will be handy as we play with 3D graphics.

OK, so ...

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.