left-icon

JavaScript Succinctly®
by Cody Lindley

Previous
Chapter

of
A
A
A

CHAPTER 16

Math Function

Math Function


Conceptual overview of the built-in Math object

The Math object contains static properties and methods for mathematically dealing with numbers or providing mathematical constants (e.g., Math.PI;). This object is built into JavaScript, as opposed to being based on a Math() constructor that creates math instances.

Notes

It might seem odd that Math starts with a capitalized letter since you do not instantiate an instance of a Math object. Do not be thrown off by this. Simply be aware that JavaScript sets this object up for you.

Math properties and methods

The Math object has the following properties and methods:

Properties (e.g., Math.PI;):

Methods (e.g., Math.random();):

Math is not a constructor function

The Math object is unlike the other built-in objects that are instantiated. Math is a one-off object created to house static properties and methods, ready to be used when dealing with numbers. Just remember, there is no way to create an instance of Math, as there is no constructor.

Math has constants you cannot augment or mutate

Many of the Math properties are constants that cannot be mutated. Since this is a departure from the mutable nature of JavaScript, these properties are in all caps (e.g., Math.PI;). Do not confuse these property constants for constructor functions due to the capitalization of their first letter. They are simply object properties that cannot be changed.

Notes

User-defined constants are not possible in JavaScript 1.5, ECMA-262, Edition 3.

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.