JavaScript Math object

reviewing this calculation-oriented built-in object
// updated 2025-05-09 11:49

The Math object built into JavaScript provides us with several mathematical functions so we don't have to write them ourselves (imagine re-inventing sines and cosines from scratch!)

Some common functions include:

  • Math.random()
    • gives us a random decimal number between 0 and 1 inclusive
  • Math.abs(someNumberOrCalculation)
    • gives us the absolute value of a number or a calcuation, e.g.
      • -1 becomes 1
      • 2 just remains 2
      • -3+2 becomes 1
  • Math.floor(someNumber)
    • gives us the integer that is less than or equal to some number, e.g.
      • 12.24 becomes 12
      • -1.37 becomes -2
      • 0 becomes 0
  • Math.ceil(someNumber)
    • gives us the integer that is greater than or equal to some number, e.g.
      • 12.24 becomes 13
      • -1.37 becomes -1
      • 0 becomes 0
  • Math.sqrt(x)
    • gives us the square root of x
  • Math.pow(x, y)
    • gives us the "x to the power of y"
  • Math.sin(x)
    • gives us the sine of x (in radians)
  • Math.cos(x)
    • gives us the cosine of x (in radians)
  • Math.tan(x)
    • gives us the tangent of x (in radians)
  • Math.asin(x) + Math.acos(x) + Math.atan(x)
    • gives us the arcsine + arccosine + arctangent of x (in radians)
  • Math.PI
    • gives us the approximation of pi (3.14159)
  • Math.E
    • gives us the approximation to Euler's constant (2.718)

Further exploration

⬅️ older (in textbook-javascript)
📒 JavaScript Date object
⬅️ older (in code)
📒 JavaScript Date object
newer (in code) ➡️
React essentials ⚛️
⬅️ older (posts)
📒 JavaScript Date object
newer (posts) ➡️
React essentials ⚛️