Skip to content
Related Articles

Related Articles

Improve Article

What is the use of Math object in JavaScript ?

  • Difficulty Level : Easy
  • Last Updated : 27 Aug, 2021

Math is an inbuilt object that has attributes and methods for mathematical functions and constants. It’s not a function object. Math object works with the Number type. The Math object does not have a constructor. All properties and methods of Math are fixed/static. The cosine function is known as Math.cos(y) while the constant pi is known as Math.PI, where y is the method’s argument. All the properties and methods of Math are static and can be called by using Math as an object without creating it. In this article, we will discuss various available methods & properties used in Javascript. We will start with the Math properties in Javascript. 

Static Math Properties: The Math properties & their descriptions are listed below: 

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

Math.property

Property

Description

Return value

Math.EEuler’s constant, the base of natural logarithms is approximately 2.718.Euler’s number
Math.LN2Natural logarithm of 2 which is approximately 0.693147180.natural logarithm of 2
Math.LN10Natural logarithm of 10 which is approximately 2.302585.natural logarithm of 10
Math.LOG2EBase-2 logarithm of E which is approximately 1.442695.base 2 logarithms of E
Math.LOG10EBase-10 logarithm of E which is approximately 0.43429844.base 10 logarithms of E
Math.PIThe ratio of the circumference of a circle to its diameter i.e. 3.14159.PI value
Math.SQRT1_2The square root of 1/2 is approximately 0.70710678.The square root of 1/2
Math.SQRT2The square root of 2 is approximately 1.41421356.The square root of 2



 

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" 
          content="IE=edge" />
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0" />
    <title>Document</title>
  </head>
    
  <body>
    <script>
      console.log("Math.PI", Math.PI);
      console.log("Math.SQRT2", Math.SQRT2);
      console.log("Math.SQRT1_2", Math.SQRT1_2);
      console.log("Math.LN10", Math.LN10);
      console.log("Math.LN2", Math.LN2);
      console.log("Math.LOG10E", Math.LOG10E);
      console.log("Math.LOG2E", Math.LOG2E);
    </script>
  </body>
</html>

Output:

Static Math Methods: The methods associated with the Math object are listed below, along with their descriptions.

Syntax:

Math.method(number)

Method

Description

Math.abs(y)The positive value of y is returned.
Math.acos(y)The arccosine of y is returned.
Math.acosh(y)Hyperbolic arccosine of y is returned.
Math.asin(y)The arcsine of y is returned.
Math.asinh(y)A number’s hyperbolic arcsine is returned.
Math.atan(y)The arctangent of y is returned.
Math.atanh(y)Returns the hyperbolic arctangent of y.
Math.atan2(y, x)The arctangent of the quotient of its arguments is returned.
Math.cbrt(y)Returns the cube root of y.
Math.ceil(y)Returns the smallest integer greater than or equal to y.
Math.clz32(y)Returns the number of leading zero bits of the 32-bit integer y.
Math.cos(y)Returns the cosine of the angle y.
Math.cosh(y)Returns the hyperbolic cosine of y.
Math.exp(y)       Returns e^(y), with x being the input and e being Euler’s constant (2.718…, the natural logarithm’s base).
Math.expm1(y)Returns subtracting 1 from exp(y).
Math.floor(y)Returns the largest integer less than or equal to y.
Math.fround(y)The nearest number’s single-precision float representation is returned.
Math.hypot([x[, y[, …]]])Returns the square root of the sum of squares of its parameters.
Math.imul(x, y)The result of the 32-bit integer multiplication of x and y is returned.
Math.log(y)Returns the natural logarithm of the number.
Math.log1p(y)For a number y, the natural logarithm of 1 + y is returned.
Math.log10(y)The base-10 logarithm of y. is returned.
Math.log2(y)The base-2 logarithm of y is returned.
Math.max([x[, y[, …]]])Largest number is returned from x,y.
Math.min([x[, y[, …]]])The smallest of all the numbers is returned from x,y.
Math.pow(x, y)Returns the exponent power y of the base value x (that is, x^y).
Math.random()An arbitrary number between 0 and 1 is returned.
Math.round(y)The value of y, rounded to the closest integer, is returned.
Math.sign(y)The sign of y, which indicates whether y is positive, negative, or zero is returned.
Math.sin(y)The sine of the angle y is returned.
Math.sinh(y)Hyperbolic sine of y is returned.
Math.sqrt(y)The positive square root of y is returned.
Math.tan(y)The tangent of y is returned.
Math.tanh(y)The hyperbolic tangent of y is returned.
Math.trunc(y)Removes all fractional digits from x and returns the integer part of it.

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" 
          content="IE=edge" />
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      console.log("ceil ", Math.ceil(9.6));
      console.log("floor ", Math.floor(9.6));
      console.log("round ", Math.round(9.6));
      console.log("sine ", Math.sin(30));
      console.log("cosine ", Math.cos(30));
      console.log("min ", Math.min(30, 40));
      console.log("max ", Math.max(30, 40));
      console.log("sign ", Math.sign(-40));
      console.log("abs ", Math.sign(-40));
    </script>
  </body>
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :