The JavaScript Math object: properties and methods
verified on 7 September 2026 · 3 min
Now that we have seen how objects work in JavaScript, we can look at a runtime object that is already built into the language, with no library to import: Math, which handles higher-level mathematical work.
If you have followed this tutorial from the start, you already know that JavaScript comes with the basic arithmetic operators (+, -, *, /) for simple operations.
However, the Math object goes much further, with a range of properties and methods that let you run complex calculations with a high degree of precision.
console.log(Math.PI); // prints 3.141592653589793
console.log(Math.abs(-10)); // prints 10
console.log(Math.pow(2, 10)); // prints 1024
console.log(Math.sqrt(25)); // prints 5
console.log(Math.cbrt(8)); // prints 2
console.log(Math.exp(2)); // prints 7.38905609893065
// etc...Properties of the JavaScript Math object
The Math object has several useful properties:
- Math.PI: returns the value of pi (3.14159). Use it for trigonometric calculations.
- Math.E: returns the value of “e” (2.71828). Use it for exponential calculations.
Here is an example of these properties in use:
let rayon = 5;
let circonference = 2 * Math.PI * rayon;
let aire = Math.PI * rayon * rayon;
console.log(`Circonférence : ${circonference}`);
// prints "Circonférence : 31.41592653589793"
console.log(`Aire : ${aire}`);
// prints "Aire : 78.53981633974483"Methods of the JavaScript Math object
The Math object also comes with plenty of methods for more complex calculations:
- Math.abs(x): returns the absolute value of x. For example, Math.abs(-5) returns 5.
- Math.ceil(x): returns the smallest integer greater than or equal to x. For example, Math.ceil(4.3) returns 5.
- Math.floor(x): returns the largest integer less than or equal to x. For example, Math.floor(4.7) returns 4.
- Math.round(x): returns the integer closest to x. For example, Math.round(4.4) returns 4, while Math.round(4.5) returns 5.
- Math.max(x, y, …): returns the largest of the values passed as arguments. For example, Math.max(4, 6, 8, 2) returns 8.
- Math.min(x, y, …): returns the smallest of the values passed as arguments. For example, Math.min(4, 6, 8, 2) returns 2.
- Math.pow(x, y): returns x to the power of y. For example, Math.pow(2, 3) returns 8.
Here is an example of these methods in use:
let nombre = -4.5;
console.log(Math.abs(nombre)); // prints 4.5
console.log(Math.ceil(nombre)); // prints -4
console.log(Math.floor(nombre)); // prints -5
console.log(Math.round(nombre)); // prints -4
console.log(Math.max(4, 6, 8, 2)); // prints 8
console.log(Math.min(4, 6, 8, 2)); // prints 2
console.log(Math.pow(2, 3)); // prints 8Other useful methods of the Math object
The Math object has a few other methods worth knowing:
- Math.random(): returns a random number between 0 and 1. It is often used to generate random numbers inside a given range. For example, to get a random number between 1 and 10:
let aleatoire = Math.floor(Math.random() * 10) + 1;- Math.sqrt(x): returns the square root of x. For example, Math.sqrt(4) returns 2.
- Math.cbrt(x): returns the cube root of x. For example, Math.cbrt(8) returns 2.
- Math.trunc(x): returns the integer part of x by dropping the decimals. For example, Math.trunc(4.7) returns 4.
console.log(Math.random()); // prints a random number between 0 and 1
console.log(Math.sqrt(4)); // prints 2
console.log(Math.cbrt(8)); // prints 2
console.log(Math.trunc(4.7)); // prints 4Conclusion
In this chapter, we saw how to use the properties and methods of the Math object in JavaScript. In particular, we saw how to perform basic calculations such as powers, square roots, rounding, truncation and absolute values. We also saw how to use the Math.max and Math.min methods to find the maximum and minimum of two or more numbers.
In the next chapter, we will manipulate the HTML page with JavaScript, using selectors and DOM methods.