The Math object is a built-in, static object in JavaScript. It’s functions and constants helps in mathematical calculations. Since math is static it can be used directly to call all it’s constants and methods.

Math Properties

Math.E

Returns Euler’s constant and base of natural logarithms.

Math.LN10

Returns natural logarithm of 10.

Math.LOG2E

Returns Base 2 logarithm of 2.

Math.LOG10E

Returns Base 10 logarithm of E.

Math.PI

Returns Pi Value.

Math.LN2

Returns Natural Logarithm of 2.

Math.SQRT1_2

Returns square root of 1/2.

Math.SQRT2

Returns square root of 2.

Example of Math object properties in JavaScript

Math Methods

Following built-in Math methods are used for mathematical functions.

Math.random()

This method returns a random number between 0 and 1.   

Example of Math.random() method 

Math.min(num1, num2, num3 ….)

This method returns the lowest number in the list of arguments passed to it.

Example of Math.min() method 

Math.max(num1, num2, num3 ….)

This method returns the highest number in the list of arguments passed to it.

Example of Math.max() method 

Math.round(num)

This method rounds the input number to nearest integer.

Example of Math.round() method 

Math.ceil(num)

This method rounds the number to the nearest higher integer.

 Example of Math.ceil() method 

Math.floor(num)

This method rounds the number to the nearest lower integer.

 Example of Math.floor() method 

Math.abs(num)

This method returns absolute value of a number.

Example of Math.abs() method 

Math.exp(num)

This method returns value of E to power num.

Example of Math.exp() method 

Math.log(num)

This method returns natural algorithm (base E) of num.

Example of Math.log() method 

Math.acos(num)

This method returns arccosine of num in radians.

Example of Math.acos() method 

Math.asin(num)

This method returns arcsine of num in radians.

Example of Math.asin() method 

Math.atan(num)

This method returns arctangent of num in numeric value between –PI/2 to PI/2.

Example of Math.atan() method 

Math.atan2(num1, num2)

This method returns arctangent of the quotient of its arguments.

Example of Math.atan2() method 

Math.cos(num)

This method returns cosine of num in radians.

Example of Math.cos() method

Math.sin(num)

This methods returns sine of number in radians.

Example of Math.sin() method

Math.tan(num)

This method returns tangent of the angle.

Example of Math.tan() method

Math.pow(num, x)

This method returns num to the power of x.

Example of Math.pow() method

Math.sqrt(num)

This method returns square root of num.

Example of Math.sqrt() method

 

›› go to examples ››