2. Numbers

There aren’t very many surprising aspects to using numbers and math in JavaScript. In fact, most of my scripts use numbers for little more than counters and simple addition. But when you’re creating complex layouts or programming animation, it’s helpful to know the ins and outs of numbers in JavaScript.

Basic Math

Most of the time you use numbers for simple math, using familiar operators.


The modulus operator (%) is great for determining whether a number is odd or even.


Operators have a specific precedence, just like we all learned ...

Get The JavaScript PocketGuide 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.