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().
Basic Math Methods
Math.round()
Rounds to the nearest integer.
Math.ceil()
Rounds up.
Math.floor()
Rounds down.
Math.trunc()
Removes decimal part.
Power & Roots
Math.pow()
Math.sqrt()
Math.cbrt()
Absolute & Sign
Math.abs()
Math.sign()
Minimum & Maximum
With arrays:
Random Numbers
Random between 0 and 1
Random between 1 and 10
Random between min and max
Trigonometric Functions
- Angles are in radians, not degrees.
Logarithmic Methods
Constants in Math
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 ofMath.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 |
