← Back to Roadmap

Math

Easy

In plain terms

Math provides mathematical constants and functions. Not a constructor - use Math.method(). Common: random, floor, ceil, round, abs, max, min, pow, sqrt.

What you need to know

  • Static methods
  • Math.random, floor, ceil, round
  • Constants: PI, E

Try it yourself

Copy the code below and run it in your browser console or a code editor:

Math.PI;           // 3.14159...
Math.random();     // 0 to 1
Math.floor(4.7);   // 4
Math.ceil(4.2);    // 5
Math.round(4.5);   // 5
Math.abs(-5);      // 5
Math.max(1,5,3);   // 5
Math.min(1,5,3);   // 1
Math.pow(2,3);     // 8
Math.sqrt(16);     // 4

// Random integer 1-10
Math.floor(Math.random() * 10) + 1;

Learn more

Dive deeper with these trusted resources: