Math in ECMAScript 262

A global, non-instantiable object which holds certain math-related functions and values.

Inherits from:

Self Methods

name returns description
abs(x) Number Return the absolute value of x.
acos(x) Number Return the arc cosine of x, in radians.
atan(x) Number Return the arc tangent of x, in radians.
atan2(y,x) Number Return the arc tangent of the quotient y/x, where the signs of y and x are used to determine the quadrant of the result, in radians.
ceil(x) Number Return smallest integer which is larger than x (aka "round up").
cos(x) Number Return the cosine of x, in radians.
exp(x) Number Return the value of ex.
floor(x) Number Return largest integer which is less than x (aka "round down").
log(x) Number Return the natural logarithm of x.
max([value1],[value2],[...]) Number Return the largest of all arguments supplied.
min([value1],[value2],[...]) Number Return the smallest of all arguments supplied.
pow(x,y) Number Return the value of raising x to the power y.
random() Number Return a floating-point random number between 0 (inclusive) and 1 (exclusive).
round(x) Number Round a number to the closest integer.
sin(x) Number Return the sine of x, in radians.
sqrt(x) Number Return the square root of x.
tan(x) Number Return the tangent of x, in radians.

Instance Properties

name type description
constructor Object A reference to the constructor class for the current object instance. [from Object]
prototype Object The prototype for a class. [from Object]

Instance Methods

name returns description
hasOwnProperty(propertyOrMethodName) Boolean Determines if the object/instance itself has the named property or method. [from Object]
isPrototypeOf(instanceToTest) Boolean Determines if the calling object prototype is in the inheritance chain for the supplied argument. [from Object]
propertyIsEnumerable(propertyOrMethodName) Boolean Determines if the object/instance itself has a property or method of the supplied name which will appear in a for (prop in obj) enumeration. [from Object]
toLocaleString() String For most objects, the same as toString() unless explicitly overridden. [from Object]
toString() String Returns a string representation of the object. [from Object]
valueOf() String Returns the internal this value of the object. [from Object]


name object value description
E Math e Roughly 2.7182818284590452354.
LN10 Math ln(10) The natural logarithm of 10, roughly 2.302585092994046
LN2 Math ln(2) The natural logarithm of 2, roughly 0.6931471805599453
PI Math π Roughly 3.1415926535897932
SQRT1_2 Math √(0.5) The square root of 1/2, roughly 0.7071067811865476
SQRT2 Math √2 The square root of 2, roughly 1.4142135623730951
LOG2E Math log2(e) The base-2 logarithm of e, roughly 1/Math.LN2 or 1.4426950408889634
LOG10E Math log10(e) The base-10 logarithm of e, roughly 1/Math.LN10 or 0.4342944819032518


The Math object is global and non-instantiable. (It is an error to do something like var x = new Math().) Invoke its methods directly as properties of the Class object itself, e.g.:

var x = 12.784;
x = Math.round(x);

...instead of the following common mistakes which are invalid:

var x = 12.784;
x.round(); // *** INVALID CODE
round(x);  // *** INVALID CODE