The Math object in JavaScript is a built-in object that provides mathematical constants and functions, such as rounding, trigonometric calculations, exponentiation, and random number generation. It is not a constructor and is used directly.
→ No, Math is not a constructor. You cannot use new Math(). Instead, you use it as a static object, like Math.round(5.5).
- Math.round() → Rounds a number to the nearest integer. If the decimal is 0.5 or higher, it rounds up; otherwise, it rounds down.
- Math.ceil() → Rounds a number up to the next largest integer, regardless of the decimal.
- Math.floor() → Rounds a number down to the next smallest integer, regardless of the decimal.
Math.random() generates a pseudo-random floating-point number between 0 (inclusive) and 1 (exclusive), such as 0.472 or 0.999.
→ It produces values in the range:
0 ≤ value < 1
1.Break the task down into components
2.Identify assumptions
3.Look for a pattern or connection
4.Create a plan (timeline & logical order)
5.Stay on track
6.Review & reflect