

The Math object allows you to perform mathematical tasks.
Math ObjectThe Math object allows you to perform mathematical tasks. The Math object includes several mathematical constants and methods. Syntax for using properties/methods of Math:
Note: Math is not a constructor. All properties and methods of Math can be called by using Math as an object without creating it. Mathematical ConstantsJavaScript provides eight mathematical constants that can be accessed from the Math object. These are: E, PI, square root of 2, square root of 1/2, natural log of 2, natural log of 10, base2 log of E, and base10 log of E. You may reference these constants from your JavaScript like this
Mathematical MethodsIn addition to the mathematical constants that can be accessed from the Math object there are also several methods available. The following example uses the round() method of the Math object to round a number to the nearest integer:
The code above will result in the following output:
The following example uses the random() method of the Math object to return a random number between 0 and 1:
The code above can result in the following output:
The following example uses the floor() and random() methods of the Math object to return a random number between 0 and 10:
The code above can result in the following output:


