JavaScript math object

In JavaScript, the function related to mathematics are implemented as methods of the math object.

The Methods of the math object are divided into two categories: Arithmetic Method and Trigonometry Method.

List of arithmetic methods

The abs() method returns the absolute value of number. The method used to find absolute value is written as Math.abs().

Example of abs() method

var a = Math.abs(-100)

var b = Math.abs(+45)

The ceil() method take a single numeric argument and returns the smallest integer that is greater then or equal to the argument. It method written as Math.ceil().

Example of ceil() method

Math.ceil(16) = 16

Math.ceil(16.01) = 17

The exp() method return Euler’s constant to the power of the specified argument (e argument). It method is written as Math.exp().

Example of exp() method

document.write(Math.exp(4)); //Output 54.598150033144236

The floor() method takes one integer argument a input and returns the greater integer that is less then or equal to the value pass to it. It written as Math.floor()

Example of floor() method

Math.floor(16) = 16

Math.floor(16.01) = 16

The log() method returns the natural logarithm of a argument passed to it. It method is written as Math.log().

Example of log() method


The max() method returns the greater of two numbers and min() returns the lesser of the two number, written as Math.max() and Math.min().

Example of max(),min() method
Math.max(100,200) = 200
Math.min(2,Math.abs(-2) = 2

The pow() method used to calculate the power of a given number. It take two numeric argument and returns the first one to the power to the second one.

Example of pow() method

Math.pow(10,2) = 100

The random() method returns a random number between 0 and 1. This number is a floating pint number.

Example of random() method

For(var i = 0 i < 5; ++i)


The round() method returns the value of a number rounded to the nearest integer. It written as Math.round().

Example of round () method

Math.round(3.7) = 4

Math.round(16.1 = 16

The sqrt() method returns the square root of the number given same argument.

Example of sqrt() method
 Math.sqrt(4) = 2
 Math.sqrt(100) = 10
List of trigonometric method

The cos() method takes one argument i.e. angle in radiant and returns the cosine of that angle.’

Example of cos() method


The acos() method also accept one argument and returns the arc cosine of the argument in radiant.

Example of acos() method

The sin() method takes one argument i.e angle is radiant and returns the sine of it,

Example of sin() method
document.write(Math.sin(0.5 * Math.pi));

The asin() method also accepts one argument and returns its arc sine in radiant.

Example of asin() method

The tan() method takes one argument i.e. the angle in radiant and returns the tangent of its argument.

Example of tan() method
 document.write(Math.tan(0.25 * Math.pi));atan()

The atan method returns the arc tangent of its argument.

Example of atan() method

var v = 0.25 * Math.pi
document.write("sine =" + Math.sin(v) + "
document.write("cosine =" + Math.sin(v) + "
document.write("tangent =" + Math.tan(v) + "<br)");

Leave a Reply