1. Math.floor(x)
Rounds a number down to the nearest integer.
console.log(Math.floor(4.9)); // 4
console.log(Math.floor(4.1)); // 4
console.log(Math.floor(-4.9)); // -5
console.log(Math.floor(-4.1)); // -5
console.log(Math.floor(0.99)); // 0
2. Math.ceil(x)
Rounds a number up to the nearest integer.
console.log(Math.ceil(4.1)); // 5
console.log(Math.ceil(4.9)); // 5
console.log(Math.ceil(-4.1)); // -4
console.log(Math.ceil(-4.9)); // -4
console.log(Math.ceil(0.01)); // 1
3. Math.round(x)
Rounds a number to the nearest integer.
console.log(Math.round(4.4)); // 4
console.log(Math.round(4.5)); // 5
console.log(Math.round(4.6)); // 5
console.log(Math.round(-4.4)); // -4
console.log(Math.round(-4.5)); // -4
console.log(Math.round(-4.6)); // -5
4. Math.trunc(x)
Removes the decimal part of a number.
console.log(Math.trunc(4.9)); // 4
console.log(Math.trunc(4.1)); // 4
console.log(Math.trunc(-4.9)); // -4
console.log(Math.trunc(-4.1)); // -4
console.log(Math.trunc(0.99)); // 0
5. Math.abs(x)
Returns the absolute value of a number.
console.log(Math.abs(4)); // 4
console.log(Math.abs(-4)); // 4
console.log(Math.abs(0)); // 0
console.log(Math.abs(-4.9));// 4.9
console.log(Math.abs(4.9)); // 4.9
6. Math.pow(base, exponent)
Calculates the power of a number (base^exponent).
console.log(Math.pow(2, 3)); // 8
console.log(Math.pow(5, 2)); // 25
console.log(Math.pow(7, 0)); // 1
console.log(Math.pow(-2, 3)); // -8
console.log(Math.pow(2, -2)); // 0.25
7. Math.sqrt(x)
Finds the square root of a number.
console.log(Math.sqrt(25)); // 5
console.log(Math.sqrt(9)); // 3
console.log(Math.sqrt(2)); // 1.414
console.log(Math.sqrt(0)); // 0
console.log(Math.sqrt(-4)); // NaN
8. Math.cbrt(x)
Finds the cube root of a number.
console.log(Math.cbrt(27)); // 3
console.log(Math.cbrt(8)); // 2
console.log(Math.cbrt(1)); // 1
console.log(Math.cbrt(-27)); // -3
console.log(Math.cbrt(125)); // 5
9. Math.max(x1, x2, ..., xn)
Returns the largest number from a given set of numbers.
console.log(Math.max(4, 7, 1, 9, 12)); // 12
console.log(Math.max(-1, -7, -5)); // -1
console.log(Math.max(3.5, 2.8, 3.9)); // 3.9
console.log(Math.max(100, 200, 50)); // 200
console.log(Math.max()); // -Infinity
10. Math.min(x1, x2, ..., xn)
Returns the smallest number from a given set of numbers.
console.log(Math.min(4, 7, 1, 9, 12)); // 1
console.log(Math.min(-1, -7, -5)); // -7
console.log(Math.min(3.5, 2.8, 3.9)); // 2.8
console.log(Math.min(100, 200, 50)); // 50
console.log(Math.min()); // Infinity
11. Math.random()
Generates a random decimal number between 0 (inclusive) and 1 (exclusive).
console.log(Math.random());
console.log(Math.random() * 10);
console.log(Math.floor(Math.random() * 100));
console.log(Math.ceil(Math.random() * 50));
console.log(Math.random() * 5 + 1);
12. .toFixed(n)
Rounds a number to n decimal places and returns it as a string.
console.log((5.6789).toFixed(2)); // "5.68"
console.log((3.14159).toFixed(3)); // "3.142"
console.log((100.567).toFixed(1)); // "100.6"
console.log((0.123456).toFixed(4));// "0.1235"