Math object is a built-in-object , hence you need not create an instance of Math object before using it using keyword new.
The Math object stores a lot of mathematical constansts, like log values, PI. It can also be used to compute power and square roots of a number.
In the below demo, constants and some simple mathematical operations are performed using Math Object .
The Math object provides methods of ceil(), floor() and round() to round off the numbers both upwards and downwards
All of these methods truncate the number provided as an argument to return a whole number rounded up based on the method used.
floor() : Method rounds numbers to the next lowest whole number, and then removes all values after decimal point.
ceil() : Method rounds numbers to the next largest whole number, and then removes all values after decimal point.
round() : Method rounds numbers to the next largest whole number for decimal values greater than .5 and to the lowest next integer for values less than 0.5.
There is always a need to generate a random number to display some random image, message, ads etc in an unbaised way, for that very purpose we use Math.random() method.
The method Math.random() generates a random fraction number between 0 to 1, hence to have integer you should multiply it with integers and then truncate numbers after decimal point using Math.floor() method.
The Math object provides methods of min() and max() are used to find the smallest and largest within a group of number.