Back to results for “Math & BigInt”
JavaScript › Numbers, Math & BigInt

What are some commonly used Math object methods?

Beginner

Answer

Math.round(), Math.floor(), and Math.ceil() handle rounding; Math.max()/Math.min() find extremes among arguments; Math.random() generates a pseudo-random float between 0 (inclusive) and 1 (exclusive); Math.abs() returns absolute value.
Math.round(4.5);   // 5
Math.floor(4.9);   // 4
Math.random();      // e.g. 0.5834...
Math.max(3, 7, 2);  // 7
Real-world example Generating a random integer within a specific range for a dice-roll or ID-suffix generator.

Common follow-ups: How do you generate a random integer between two specific values using Math.random()?