Math

A built-in object that has properties and methods for mathematical constants and functions. For example, the Math object's PI property has the value of pi. Math is a core object.

Created by

The Math object is a top-level, predefined JavaScript object. You can automatically access it without using a constructor or calling a method.

Description

All properties and methods of Math are static. You refer to the constant PI as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument. Constants are defined with the full precision of real numbers in JavaScript.

It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example:

with (Math) {
      a = PI * r*r
      y = r*sin(theta)
      x = r*cos(theta)
}