JavaScript Math
JavaScript Math
In JavaScript Math provides a built-in Math object to perform mathematical operations.
It is not a constructor — you use it directly: Math.method().
1️⃣ Basic Math Methods
🔹 Math.round()
Rounds to the nearest integer.
🔹 Math.ceil()
Rounds up.
🔹 Math.floor()
Rounds down.
🔹 Math.trunc()
Removes decimal part.
2️⃣ Power & Roots
🔹 Math.pow()
🔹 Math.sqrt()
🔹 Math.cbrt()
3️⃣ Absolute & Sign
🔹 Math.abs()
🔹 Math.sign()
4️⃣ Minimum & Maximum
With arrays:
5️⃣ Random Numbers 🎲
🔹 Random between 0 and 1
🔹 Random between 1 and 10
🔹 Random between min and max
6️⃣ Trigonometric Functions
📌 Angles are in radians, not degrees.
7️⃣ Logarithmic Methods
8️⃣ Constants in Math
9️⃣ Practical Examples
✔ Find Area of Circle
✔ Round Price for Billing
✔ Generate OTP
Common Mistakes ❌
❌ new Math() → invalid
❌ Forgetting radians in trigonometry
❌ Using Math.round() instead of Math.floor() for random numbers
Quick Summary 📌
| Method | Purpose |
|---|---|
round() |
Nearest integer |
ceil() |
Round up |
floor() |
Round down |
random() |
Random number |
pow() |
Power |
sqrt() |
Square root |
min()/max() |
Smallest / Largest |
