HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

JavaScript Math Object

The Math object in JavaScript provides a set of mathematical operations and constants. It contains properties and methods for mathematical calculations.

Here's an overview of the Math object in JavaScript:

Properties:

  • Math.E: Euler's constant, approximately 2.718.
  • Math.PI:The ratio of the circumference of a circle to its diameter, approximately 3.14159.

Example

              

Math.PI;

Methods:

  • Math.abs(x): Returns the absolute value of a number.

  • Math.ceil(x): Returns the smallest integer greater than or equal to a given number.

  • Math.floor(x): Returns the largest integer less than or equal to a given number.

  • Math.round(x): Returns the value of a number rounded to the nearest integer.

  • Math.max(x1, x2, ..., xn): Returns the largest of zero or more numbers.

  • Math.min(x1, x2, ..., xn): Returns the smallest of zero or more numbers.

  • Math.pow(x, y): Returns the base to the exponent power, that is, x raised to the power y.

  • Math.sqrt(x): Returns the square root of a number.

  • Math.exp(x): Returns Euler's number (e) raised to the power of x.

  • Math.log(x): Returns the natural logarithm (base e) of a number.

  • Math.random(): Returns a pseudo-random number between 0 and 1.

  • Math.sin(x): Returns the sine of a number.

  • Math.cos(x): Returns the cosine of a number.

  • Math.tan(x): Returns the tangent of a number.

  • Math.asin(x): Returns the arcsine (in radians) of a number.

  • Math.acos(x): Returns the arccosine (in radians) of a number.

  • Math.atan(x): Returns the arctangent (in radians) of a number.

  • Math.atan2(y, x): Returns the arctangent of the quotient of its arguments.

  • Math.sinh(x): Returns the hyperbolic sine of a number.

  • Math.cosh(x): Returns the hyperbolic cosine of a number.

  • Math.tanh(x): Returns the hyperbolic tangent of a number.

  • Math.asinh(x): Returns the inverse hyperbolic sine of a number.

  • Math.acosh(x): Returns the inverse hyperbolic cosine of a number.

  • Math.atanh(x): Returns the inverse hyperbolic tangent of a number.