The Math object allows us to perform more mathematical operations on numbers and access important mathematical values.
The Math object has several properties on it that correspond with important mathematical values, like pi.
To write a property from the Math object, write the word Math, a period, and then the name of the property written in all caps, like this (replace PROP with the actual property name):
Here are some examples of the properties on the Math object.
To write a method from the Math object, write the word Math, a period, the method name, a parentheses, and a number inside the parentheses (or a variable containing a number).
Here’s an example of the square root method being used:
Math.sqrt(4); // output: 2
For a full list of the Math objects properties and methods, visit the link in the References section.
Try the following statements in the console:
Math.PI Math.sqrt(4) Math.sqrt(9)