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.

image

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

image

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

Get The JavaScript PocketGuide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.