Skip to content

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.

  • 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.
console.log(Math.PI); // 3.141592653589793
console.log(Math.abs(-5)); // 5
console.log(Math.ceil(4.2)); // 5
console.log(Math.floor(4.9)); // 4
console.log(Math.round(4.5)); // 5
console.log(Math.max(10, 20, 5)); // 20
console.log(Math.random()); // random number between 0 and 1
console.log(Math.sqrt(16)); // 4
console.log(Math.pow(2, 3)); // 8