Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Podia.

Math object – JavaScript

Length: 10 minutes

Summary

Math.PI;
Math.sqrt(4);

Details

The Math object allows us to perform more mathematical operations on numbers and access important mathematical values.

Properties

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):

Math.PROP;

Here are some examples of the properties on the Math object.

Math.E;
Math.PI;

Methods

The Math object has several methods on it that allow you to perform other mathematical operations in JavaScript.

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

Full list

For a full list of the Math objects properties and methods, visit the link in the References section.

Demo

Exercises

Try the following statements in the console:

Math.PI
Math.sqrt(4)
Math.sqrt(9)

References

Math object on MDN

Back to: JavaScript Reference > JS Data Types