...

Web Technologies - JAVASCRIPT

Back to Course

Lesson Description


Lession - #226 Javascript Math


Math methods

The absolute value of x is returned by Math.abs(x>
.

Math.acos(x>
The arccosine of x is returned.

Math.acosh(x>
The hyperbolic arccosine of x is returned.

Math.asin(x>
The arcsine of x is returned.

Math.asinh(x>
Returns a number's hyperbolic arcsine.

Math.atan(x>
The arctangent of x is returned.

Math.atanh(x>
The hyperbolic arctangent of x is returned.

atan2.math (y, x>
The arctangent of the quotient of its arguments is returned.

Math.cbrt(x>
The cube root of x is returned.

Math.ceil(x>
The lowest integer bigger than or equal to x is returned.

Math.clz32(x>
The number of leading zero bits in the 32-bit integer x is returned.

Math.cos(x>
The cosine of x is returned.

Math.cosh(x>
The hyperbolic cosine of x is returned.

Math.exp(x>
Returns ex, with x being the input and e being Euler's constant (2.718..., the natural logarithm's base>
.

Math.expm1(x>
returns the result of subtracting 1 from exp (x>
.

The greatest integer less than or equal to x is returned by Math.floor(x>
.

The closest single precision float representation of x is returned by Math.fround(x>
.

[x[, y[,...]]] Math.hypot([x[, y[,...]]]>
Returns the square root of the sum of its inputs' squares.

Math.imul(x, y>
returns the result of x and y's 32-bit integer multiplication.

Math.log(x>
returns x's natural logarithm (loge; also, ln>
.

For the integer x, Math.log1p(x>
returns the natural logarithm (loge; sometimes ln>

1 + x.

The base-10 logarithm of x is returned by Math.log10(x>
.

The base-2 logarithm of x is returned by Math.log2(x>
.

Math.max([x, y,...]]>
The biggest of zero or more numbers is returned.

Math.min([x, y,...]]>
The smallest of zero or more numbers is returned.

arithmetic.pow (x, y>
Returns the exponent power y of base x (that is, xy>
.

Math.random(>
generates a value between 0 and 1 that is pseudo-random.

Math.round(x>
returns the rounded integer value of the number x.

Math.sign(x>
returns the x's sign, showing whether it is positive, negative, or zero.

The sine of x is returned by Math.sin(x>
.

The hyperbolic sine of x is returned by Math.sinh(x>
.

The positive square root of x is returned by Math.sqrt(x>
.

The tangent of x is returned by Math.tan(x>
.

The hyperbolic tangent of x is returned by Math.tanh(x>
.

Math.trunc(x>
returns the integer component of x, discarding any fractional digits.

Example 1: This example use math object properties to return their values.

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        JavaScript Math Object
    </title> 
</head> 
      
<body> 
  
    <h1>GeeksforGeeks</h1> 
          
    <h2>JavaScript Math Object</h2> 
  
    <p id="GFG"></p>
      
    <!-- Script to return math property values -->    
    <script> 
        document.getElementById("GFG">
.innerHTML = "Math.LN10: " + Math.LN10 + "<br>" + "Math.LOG2E: " + Math.LOG2E + "<br>" + "Math.Log10E: " + Math.LOG10E + "<br>" + "Math.SQRT2: " + Math.SQRT2 + "<br>" + "Math.SQRT1_2: " + Math.SQRT1_2 + "<br>" + "Math.LN2: " + Math.LN2 + "<br>" + "Math.E: " + Math.E + "<br>" + "Math.PI: " + Math.PI; </script> </body> </html>


Sorry cannot be displayed
Try it here

Example 2: Math object methods are used in this example.

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        JavaScript Math Object
    </title> 
</head> 
      
<body> 
  
    <h1>GeeksForGeeks</h1> 
          
    <h2>JavaScript Math Object</h2> 
  
    <p id="GFG" style = "color:green;"></p>
      
    <!-- Script to use math object method -->    
    <script> 
        document.getElementById("GFG">
.innerHTML = "<p><b>Math.abs(-4.7>
:</b> " + Math.abs(-4.7>
+ "</p>" + "<p><b>Math.ceil(4.4>
:</b> " + Math.ceil(4.4>
+ "</p>" + "<p><b>Math.floor(4.7>
:</b> " + Math.floor(4.7>
+ "</p>" + "<p><b>Math.sin(90 * Math.PI / 180>
:</b> " + Math.sin(90 * Math.PI / 180>
+ "</p>" + "<p><b>Math.min(0, 150, 30, 20, -8, -200>
:</b> " + Math.min(0, 150, 30, 20, -8, -200>
+ "</p>" + "<p><b>Math.random(>
:</b> " + Math.random(>
+ "</p>"; </script> </body> </html>


Output:
Sorry cannot be displayed
Try it here