The JavaScript Math object is a global object.
Math is not a constructor. Math is a static object, meaning that it's properties and methods are static and are accessible without an instance of the object.
For example, to get the absolute value of a number one needs to call the Math.abs() function. Creating an instance of the Math objects results in an error:
var my_math = new Math(); // wrong, throws an TypeError
Math.abs(-123); // 123Likewise, you refer to the constant pi as Math.PI.
ELN2LN10LOG2ELOG10EPISQRT1_21 / 2, equivalent to 1 / Math.sqrt(2) (0.707)SQRT2Math.sqrt(2) (1.414)abs(number)acos(number)Math.cos()asin(number)atan(number)atan2(y, x)ceil(number)cos(number)exp(e)Math.E) raised to the power of x, equivalent to Math.pow(Math.E, x)floor(number)log(x)max([value1 [ , value2 [ , ...]]])min([value1 [ , value2 [ , ...]]])pow(base, exponent)random()round(number)sin(number)sqrt(number)tan(number)If you see a typo, want to make a suggestion or have anything in particular you'd like to know more about, please drop us an e-mail at hello at diveintojavascript dot com.
Copyright © 2010-2011 Dive Into JavaScript