Math object is a built-in object that provides mathematical constants and functions for performing mathematical operations.
Math object includes multiple methods and properties for mathematical calculation.
There is various Math object in JavaScript:
// Math Constant
console.log(Math.PI); // Output: 3.1415
console.log(Math.E); // Output: 2.7182
// Math Methods
let absoluteValue = Math.abs(-34); // 34
let mathCeil = Math.ceil(5.2); // 6
let mathFloor = Math.floor(4.7); // 4
let mathRound = Math.round(3.6); // 4
let minNum = Math.min(10, 20, 5, 30); // 5
let maxNum = Math.max(10, 20, 5, 30); // 30
// Exponential & logarithmic methods
let mathPow = Math.pow(2, 3); // 2 raised to 3 -> 8
let mathExp = Math.exp(4); // e raised to the power of 4
let mathLog = Math.log(20); // log of 20
Math.random(): Returns a pseudo-random number between 0 (inclusive) and 1 (exclusive).
// Random number methods
let mathRandom = Math.random(0, 1); // value between 0 & 1