JavaScript Math Reference Manual

Math object

The Math object allows you to perform mathematical tasks.

Math is not a constructor. All properties/methods of Math can be called using Math as an object without creating it:

var x = Math.PI;            // Returns PI
var y = Math.sqrt(16);      // Returns the square root of 16

Try It Yourself

For tutorials on the Math object, please read our JavaScript Math Tutorial.

Math object properties

Properties Description
E Return Euler's number (about 2.718).
LN2 Return the natural logarithm of 2 (about 0.693).
LN10 Return the natural logarithm of 10 (about 2.302).
LOG2E Return the logarithm of E with base 2 (about 1.442).
LOG10E Return the logarithm of E with base 10 (about 0.434).
PI Return PI (about 3.14).
SQRT1_2 Return the square root of 1/2 (about 0.707).
SQRT2 Return the square root of 2 (about 1.414).

Math object methods

Method Description
abs(x) Return the absolute value of x.
acos(x) Return the arccosine of x, in radians.
acosh(x) Return the hyperbolic arccosine of x.
asin(x) Return the arcsine of x, in radians.
asinh(x) Return the hyperbolic arcsine of x.
atan(x) Return the arctangent of x, the returned value is an angle between -PI/2 and PI/2 radians.
atan2(y, x) Return the arctangent of the quotient of its parameters.
atanh(x) Return the hyperbolic arctangent of x.
cbrt(x) Return the cube root of x.
ceil(x) Return x, rounded up to the nearest integer.
clz32(x) Return the number of leading zeros in the 32-bit binary representation of x.
cos(x) Return the cosine of x (x is in radians).
cosh(x) Return the hyperbolic cosine of x.
exp(x) Return the value of e raised to the power of x.
expm1(x) Return the value of e raised to the power of x minus 1.
floor(x) Return x, rounded down to the nearest integer.
fround(x) Return the closest floating-point representation of the number (32-bit single precision).
log(x) Return the natural logarithm of x.
log10(x) Return the logarithm of x with base 10.
log1p(x) Return the natural logarithm of 1 + x.
log2(x) Return the logarithm of x with base 2.
max(x, y, z, ... , n) The highest return value is a number.
min(x, y, z, ... , n) The smallest return value is a number.
pow(x, y) Returns the value of x to the power of y.
random() Returns a random number between 0 and 1.
round(x) Rounds x to the nearest integer.
sign(x) Returns the sign of a number (check if it is positive, negative, or zero).
sin(x) Returns the sine of x (x is in radians).
sinh(x) Returns the hyperbolic sine of x.
sqrt(x) Returns the square root of x.
tan(x) Returns the tangent of an angle.
tanh(x) Returns the hyperbolic tangent of a number.
trunc(x) Returns the integer part of the number (x).