What does the Math object provide?
The Math object is a group of built-in functions for working with numbers. None of its functions need a receiver, so you always call them by writing Math in front of the name.
console.log(Math.max(3, 1, 7)); // 7
console.log(Math.min(3, 1, 7)); // 1
console.log(Math.round(2.5)); // 3
console.log(Math.floor(2.9)); // 2
console.log(Math.ceil(2.1)); // 3
console.log(Math.trunc(-2.9)); // -2
console.log(Math.abs(-5)); // 5
console.log(Math.pow(2, 10)); // 1024
console.log(Math.sqrt(16)); // 4
console.log(Math.sign(-3)); // -1
The rounding family is the part that is worth learning properly, because the members treat negative numbers differently. Math.floor() always rounds down, so it moves towards negative infinity. Math.ceil() always rounds up, so it moves towards positive infinity. Math.trunc() throws the decimal part away, so it moves towards zero. And Math.round() gives the nearest whole number, where a halfway value moves towards positive infinity, which means a negative halfway value moves up towards zero.
There are also limits for numbers. The largest safe integer is the biggest whole number that a double can hold exactly, and that is about nine quadrillion. Any number above it starts to lose precision, and the very largest number that JavaScript can write is not a whole number at all. The epsilon constant is the small gap between one and the next number that can be stored, and it is the usual trick for putting right a rounding error that came from floating point maths.
The Math object also holds the trigonometry functions, the logarithm and the power function, their hyperbolic versions, and a few helpers such as the sign function and the random number generator.