🔢 JavaScript Math Object
Last Updated: 26th October 2025
JavaScript provides a built-in Math object to perform mathematical operations.
Hinglish Tip 🗣: Socho Math object ek toolkit hai — har tarah ke calculation ke liye ready-made functions milte hain.
🧩 Common Math Functions
- Math.abs() → Returns the absolute value of a number.
- Math.ceil() → Returns the smallest integer greater than or equal to a number.
- Math.floor() → Returns the largest integer less than or equal to a number.
- Math.round() → Returns the value of a number rounded to the nearest integer.
- Math.random() → Returns a random number between 0 (inclusive) and 1 (exclusive).
- Math.sqrt() → Returns the square root of a number.
- Math.pow() → Returns the value of a number raised to the power of another number.
- Math.min() → Returns the minimum value of a set of numbers.
- Math.max() → Returns the maximum value of a set of numbers.
console.log(Math.abs(-5)); // 5
console.log(Math.ceil(4.2)); // 5
console.log(Math.floor(4.8)); // 4
console.log(Math.round(4.5)); // 5
console.log(Math.random()); // random number between 0 and 1
console.log(Math.sqrt(25)); // 5
console.log(Math.pow(2, 3)); // 8
console.log(Math.min(1, 2, 3, 4, 5)); // 1
console.log(Math.max(1, 2, 3, 4, 5)); // 5
Properties
- Math.E → The base of natural logarithms.
- Math.PI → The ratio of a circle's circumference to its diameter.
- Math.SQRT1_2 → The square root of 1/2.
- Math.SQRT2 → The square root of 2.
console.log(Math.E); // 2.718281828459045
console.log(Math.PI); // 3.141592653589793
console.log(Math.SQRT1_2); // 0.7071067811865476
console.log(Math.SQRT2); // 1.4142135623730951
💡 Quick Practice
- Use Math.random() to generate a random number between 1 and 10.
- Use Math.floor() to round a number down to the nearest integer.
- Use Math.ceil() to round a number up to the nearest integer.
- Use Math.round() to round a number to the nearest integer.
- Use Math.abs() to get the absolute value of a number.
- Use Math.sqrt() to calculate the square root of a number.