DEV Community

Cover image for JavaScript Math Reference
Karthick (k)
Karthick (k)

Posted on

JavaScript Math Reference

This guide is your complete reference to every Math property and method in JavaScript, all in one place — clean, concise, and ready to bookmark.

What is the Math Object?

The Math object in JavaScript lets you perform mathematical operations on numbers — everything from trigonometry and logarithms to rounding and random generation.

Math.sqrt(16); // 4
Math.PI;       // 3.141592653589793
Math.random(); // 0.5739201837
Enter fullscreen mode Exit fullscreen mode

Commonly Used Examples

Math.max(10, 20, 5);  // → 20
Math.min(2, -3, 7);   // → -3
Math.pow(2, 3);       // → 8
Math.sign(-12);       // → -1
Math.floor(4.9);      // → 4
Math.random();        // → random value between 0–1
Enter fullscreen mode Exit fullscreen mode

Want a random integer between 1 and 6 (like a dice roll)? Here’s your quick snippet:

Math.floor(Math.random() * 6) + 1;
Enter fullscreen mode Exit fullscreen mode

More References

For a complete deep-dive on all JavaScript methods, syntax, and advanced examples, check the official MDN documentation or your favourite JS reference site.
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math)

Thank you.

Top comments (0)