JavaScript Math Object

The Math object enables you to perform scientific assignments on numbers.

The Math Object

The Math object enables you to perform scientific tasks.

The Math object incorporates a few scientific methods.

One basic utilization of the Math object is to make an arbitrary number:


Math.random();       /restores an arbitrary number
Try it yourself »

Math.min() and Math.max()

Math.min() and Math.max() can be utilized to locate the most minimal or most elevated an incentive in a rundown of arguments:


Math.min(0, 150, 30, 20, - 8, - 200);     /returns - 200
Try it yourself »


Math.max(0, 150, 30, 20, - 8, - 200);      /returns 150
Try it yourself »


Math.random() restores an irregular number between 0 (inclusive),  and 1 (exclusive):


Math.random();              //restores an irregular number
Try it Yourself »


Math.round() rounds a number to the closest integer:


Math.round(4.7);            //returns 5
Math.round(4.4);            //returns 4
Try it Yourself »


Math.ceil() rounds a number up to the closest integer:


Math.ceil(4.4);             /returns 5
Try it Yourself »


Math.floor() rounds a number down to the closest integer:


Math.floor(4.7);            //returns 4
Try it Yourself »

Math.floor() and Math.random() can be utilized together to restore an irregular number somewhere in the range of 0 and 10:


Math.floor(Math.random() * 11);   //restores an irregular number somewhere in the range of 0 and 10
Try it Yourself »

Math Constants

JavaScript gives 8 scientific constants that can be gotten to with the Math object:


Math.E         /restores Euler's number
Math.PI        /returns PI
Math.SQRT2      /restores the square base of 2
Math.SQRT1_2    /restores the square base of 1/2
Math.LN2        /restores the common logarithm of 2
Math.LN10       /restores the common logarithm of 10
Math.LOG2E      /returns base 2 logarithm of E
Math.LOG10E     /returns base 10 logarithm of E
Try it yourself »

Math Object Methods

Method Description
abs(x) Returns the total estimation of x
acos(x) Returns the arccosine of x, in radians
asin(x) Returns the arcsine of x, in radians
atan(x) Returns the arctangent of x as a numeric incentive between - PI/2 and PI/2 radians
atan2(y,x) Returns the arctangent of the remainder of its arguments
ceil(x) Returns x, adjusted upwards to the closest integer
cos(x) Returns the cosine of (x is in radians)
exp(x) Returns the estimation of Ex
floor(x) Returns x, adjusted downwards to the closest integer
log(x) Returns the regular logarithm (base E) of x
max(x,y,z,...,n) Returns the number with the most astounding value
min(x,y,z,...,n) Returns the number with the most reduced value
pow(x,y) Returns the estimation of x to the intensity of y
random() Returns an irregular number somewhere in the range of 0 and 1
round(x) Rounds x to the closest integer
sin(x) Returns the sine of (x is in radians)
sqrt(x) Returns the square foundation of x
tan(x) Returns the digression of an angle