Math

The Math object allows performing mathematical operations in JavaScript. The Math object is static and doesn't have a constructor. One can use method and properties of Math object without creating a Math object first. For accessing its property one can use Math.property. Some of the math properties are described below:

Math.E        // returns Euler's number
Math.PI       // returns PI
Math.SQRT2    // returns the square root of 2
Math.SQRT1_2  // returns the square root of 1/2
Math.LN2      // returns the natural logarithm of 2
Math.LN10     // returns the natural logarithm of 10
Math.LOG2E    // returns base 2 logarithm of E
Math.LOG10E   // returns base 10 logarithm of E

To access its method, one can call its methods directly with arguments wherever necessary.

Method
Description

abs(x)

Returns absolute value of x

acos(x)

Returns arccosine of x, in radians

acosh(x)

Returns hyperbolic arccosine of x

asin(x)

Returns arcsine of x, in radians

asinh(x)

Returns hyperbolic arcsine of x

atan(x)

Returns arctangent of x as a numeric value between -PI/2 and PI/2 radians

atan2(y,x)

Returns arctangent of the quotient of its arguments

atanh(x)

Returns hyperbolic arctangent of x

crbt(x)

Returns cubic root of x

ceil(x)

Returns rounded upwards to the nearest integer of x

cos(x)

Returns consine of x, in radians

cosh(x)

Returns hyperbolic cosine of x

exp(x)

Returns exponential value of x

floor(x)

Returns round downwards to the neareast integer of x

log(x)

Returns natural logarithmetic of x

max(x,y,z,... n)

Returns number with the highest value

min(x,y,z,... n)

Returns number with the lowest value

pow(x,y)

Returns value of x to the power of y

random()

Returns number between 0 and 1

round(x)

Rounds number to the neareast x

sign(x)

Returns if x is negative, null or positive (-1,0,1)

sin(x)

Returns sine of x, in radians

sinh(x)

Returns hyperbolic sine of x

sqrt(x)

Returns square root of x

tan(x)

Returns tangent of an angle

tanh(x)

Returns hyperbolic tangent of x

trunc(x)

Returns integer part of a number (x)

An example of some of the Math methods is shown below

Last updated