Random number

        
          Math.random();
        
      

Result:

Random number with min and max

        
        function getRandomIntInclusive(min, max) {
          min = Math.ceil(min);
          max = Math.floor(max);
          return Math.floor(Math.random() * (max - min + 1) + min);
          //The maximum is inclusive and the minimum is inclusive
        }
        
      

        getRandomIntInclusive(5, 20)
      

Result:

PI

        
          Math.PI;
        
      

Result:

PI used in a function

        
          function calculateCircumference(radius) {
            return Math.PI * (radius + radius);
          }

          calculateCircumference(10);
        
      

Result:

Hypotenuse

Returns the square root of the sum of squares of its arguments. Can be used to get distance between 2 x,y coordinates

a2 + b2 = c2
        
        function getDistance(x1, x2, y1, y2) {
          return Math.hypot(x2-x1, y2-y1);
        }
        getDistance(12,30,18,60);
        
      

Result:

Round Up

        
        Math.ceil(7.12345);
        
      

Result:

Round Down

        
        Math.floor(7.12345);
        
      

Result: