Loading...
Loading...
00:00:00

Properties and Methods of Math Object

In JavaScript, the Math object is a built-in object that provides mathematical constants and functions. It is not a constructor and its properties and methods are all static. This means that you do not need to create an instance of the Math object to use its methods and properties.

Here are some of the methods and properties of the Math object:

  1. Properties:
  • Math.PI: returns the value of pi (3.141592653589793)
  • Math.E: returns the value of e (2.718281828459045)
  • Math.LN2: returns the natural logarithm of 2 (0.6931471805599453)
  • Math.LN10: returns the natural logarithm of 10 (2.302585092994046)
  1. Methods:
  • Math.abs(x): returns the absolute value of x
  • Math.ceil(x): returns the smallest integer greater than or equal to x
  • Math.floor(x): returns the largest integer less than or equal to x
  • Math.max(x1, x2, ..., xn): returns the largest of the specified values
  • Math.min(x1, x2, ..., xn): returns the smallest of the specified values
  • Math.pow(x, y): returns the value of x to the power of y
  • Math.sqrt(x): returns the square root of x
  • Math.round(x): returns the value of x rounded to the nearest integer
  • Math.random(): returns a random number between 0 and 1
  • Math.sin(x): returns the sine of x
  • Math.cos(x): returns the cosine of x
  • Math.tan(x): returns the tangent of x
  • Math.asin(x): returns the arcsine of x
  • Math.acos(x): returns the arccosine of x
  • Math.atan(x): returns the arctangent of x
  • Math.log(x): returns the natural logarithm (base e) of x
  • Math.exp(x): returns the value of e to the power of x
  • Math.atan2(y, x): returns the angle between the positive x-axis and the point (x,y)

Here's an example of how to use some of the methods of the Math object:

console.log(Math.PI); // Output: 3.141592653589793
console.log(Math.sqrt(25)); // Output: 5
console.log(Math.random()); // Output: a random number between 0 and 1

The Math object is a useful tool for performing mathematical operations in JavaScript, and can help to simplify complex calculations.