O'Reilly logo

The JavaScript PocketGuide by Lenny Burdette

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required