Math Object
The Math object is a built‑in object that provides mathematical constants and functions. It is not a constructor; all properties and methods are static.
Key Points
Section titled “Key Points”- Constants:
Math.PI,Math.E,Math.SQRT2. - Methods:
Math.abs(),Math.ceil(),Math.floor(),Math.round(),Math.max(),Math.min(),Math.random(),Math.sqrt(),Math.pow(), trigonometric functions.
Code Example
Section titled “Code Example”console.log(Math.PI); // 3.141592653589793console.log(Math.abs(-5)); // 5console.log(Math.ceil(4.2)); // 5console.log(Math.floor(4.9)); // 4console.log(Math.round(4.5)); // 5console.log(Math.max(10, 20, 5)); // 20console.log(Math.random()); // random number between 0 and 1console.log(Math.sqrt(16)); // 4console.log(Math.pow(2, 3)); // 8