Math

The Math Global Object

In JavaScript, Math is a built in global object that provides a collection of methods for performing mathematical operations. These methods are called using the syntax Math.method(). Here are some of the commonly used methods:

  • Math.abs(x): Returns the absolute value of x.
  • Math.floor(x): Returns the largest integer less than or equal to x.
  • Math.log(x): Returns the natural logarithm (base e) of x.
  • Math.max(x1, x2, ...): Returns the largest of the numbers provided.
  • Math.pow(base, exponent): Raises the base to the power of the exponent.
  • Math.random(): Returns a random floating-point number between 0 (inclusive) and 1 (exclusive).
  • Math.round(x): Rounds x to the nearest integer.
  • Math.sin(x): Returns the sine of x (x is in radians).
  • Math.sqrt(x): Returns the square root of x.