Math is oneof JavaScript's global or standard built-in objects, and can be used anywhere you
can use JavaScript.
It contains useful constants like π and Euler’s constant and functions such as floor(), round(),
and ceil().
Example
The following example shows how to use the Math object to write a function that calculates the
area of a circle
3.
Math.abs(x): Returns theabsolute value of a number x.
Math.abs(-5); // Returns 5
Math.ceil(x): Returns the smallest integer greater than or equal to a number x.
Math.ceil(4.3); // Returns 5
Math.floor(x): Returns the largest integer less than or equal to a number x.
Math.floor(4.7); // Returns 4
4.
Math.round(x): Returns thevalue of a number x rounded to the nearest integer.
Math.round(4.5); // Returns 5
Math.max(x1, x2, ...): Returns the largest of zero or more numbers.
Math.max(10, 5, 8); // Returns 10
Math.min(x1, x2, ...): Returns the smallest of zero or more
numbers.
Math.min(10, 5, 8); // Returns 5
5.
Math.pow(x, y): Returnsthe base to the exponent power, that is, x raised to the power y.
Math.pow(2, 3); // Returns 8
Math.sqrt(x): Returns the square root of a number x.
Math.sqrt(9); // Returns 3
Math.random(): Returns a random floating-point number between
0 (inclusive) and 1 (exclusive).
Math.random(); // Returns a random number between 0 and 1
6.
Math.PI: A propertyrepresenting the ratio of the
circumference of a circle to its diameter,
approximately equal to 3.14159.
Math.PI; // Returns 3.141592653589793