The JavaScript math object provides several constants and methods to perform mathematical operation. Unlike date object, it doesn't have constructors.
Let's see the list of JavaScript Math methods with description.
| Methods | Description |
|---|---|
| abs() | It returns the absolute value of the given number. |
| acos() | It returns the arccosine of the given number in radians. |
| asin() | It returns the arcsine of the given number in radians. |
| atan() | It returns the arc-tangent of the given number in radians. |
| cbrt() | It returns the cube root of the given number. |
| ceil() | It returns a smallest integer value, greater than or equal to the given number. |
| cos() | It returns the cosine of the given number. |
| cosh() | It returns the hyperbolic cosine of the given number. |
| exp() | It returns the exponential form of the given number. |
| floor() | It returns largest integer value, lower than or equal to the given number. |
| hypot() | It returns square root of sum of the squares of given numbers. |
| log() | It returns natural logarithm of a number. |
| max() | It returns maximum value of the given numbers. |
| min() | It returns minimum value of the given numbers. |
| pow() | It returns value of base to the power of exponent. |
| random() | It returns random number between 0 (inclusive) and 1 (exclusive). |
| round() | It returns closest integer value of the given number. |
| sign() | It returns the sign of the given number |
| sin() | It returns the sine of the given number. |
| sinh() | It returns the hyperbolic sine of the given number. |
| sqrt() | It returns the square root of the given number |
| tan() | It returns the tangent of the given number. |
| tanh() | It returns the hyperbolic tangent of the given number. |
| trunc() | It returns an integer part of the given number. |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
/* Ceil Method Example */
var a = Math.ceil(1.2);
document.write(a + "<br>");
/* Floor Method */
var b = Math.floor(5.10);
document.write(b + "<br>");
/* Round Method */
var c = Math.round(2.60);
document.write(c + "<br>");
/* Trunc Method */
var d = Math.trunc(8.19);
document.write(d + "<br>");
/* Max Method */
var i = Math.max(8, 10 ,2 ,50 ,25);
document.write(i + "<br>");
/* Min Method */
var j = Math.min(8, 10, 2, 50, 25);
document.write(j + "<br>");
/* Sqrt Method */
var k = Math.sqrt(64);
document.write(k + "<br>");
/* Cbrt Method */
var l = Math.cbrt(125);
document.write(l + "<br>");
/*Pow Method */
var p = Math.pow(2,3);
document.write(p + "<br>");
/*Random Method */
var x = Math.floor(Math.random() * 10) + 1;
document.write(x + "<br>");
/*Abs Method */
var y = Math.abs(5.25);
document.write(y + "<br>");
/*Pi Method */
var z = Math.PI;
document.write(z + "<br>");
</script>
</head>
<body>
</body>
</html>