Chapter 16. The Math, Number, and Boolean Objects

IN THIS CHAPTER

  • Advanced math operations

  • Number base conversions

  • Working with integers and floating-point numbers

The introduction to data types and values in Chapter 8's tutorial scratched the surface of JavaScript's numeric and Boolean powers. In this chapter, you look more closely at JavaScript's way of working with numbers and Boolean data.

Math often frightens away budding programmers. As you've seen so far in this book, however, you don't really have to be a math genius to program in JavaScript. The powers described in this chapter are here when you need them—if you need them. So if math is not your strong suit, don't freak out over the terminology here.

An important point to remember about the objects described in this chapter is that (like string values and string objects) numbers and Booleans are both values and objects. Fortunately for script writers, the differentiation is rarely, if ever, a factor, unless you get into some very sophisticated programming. To those who actually write the JavaScript interpreters inside the browsers we use, the distinctions are vital.

For most scripters, the information about numeric data types and conversions, as well as the Math object, are important to know.

Numbers in JavaScript

More powerful programming languages have many different kinds of numbers, each related to the amount of memory the number occupies in the computer. Managing all these different types may be fun for some, but it gets in ...

Get JavaScript® Bible, Seventh 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.