Methods
Math Method
The Math Object contains a list of methods which are used in performing mathematical tasks are as follows:
|
Method |
Description |
|---|---|
|
abs() |
In order to get the absolute value of a number. |
|
acos() |
In order to get the arccosine (in radians) of a number. |
|
asin() |
In order to get the arcsine (in radians) of a number. |
|
atan() |
In order to get the arctangent (in radians) of a number. |
|
atan2() |
In order to get the arctangent of the quotient of its arguments. |
|
ceil() |
In order to get the smallest integer, greater than or equal to a number. |
|
cos() |
In order to get the cosine of a number. |
|
exp() |
In order to get the Ex, where x is the argument, and E is Euler’s constant, the base of the natural logarithms. |
|
floor() |
In order to get the largest integer, less than or equal to a number. |
|
log() |
In order to get the natural logarithm (base E) of a number. |
|
max() |
In order to get the larger of two given numbers. |
|
min() |
In order to get the smaller of two given numbers. |
|
pow() |
In order to get the base to the exponent power, that is, baseexponent. |
|
random() |
In order to get the pseudo-random number between 0 and 1. |
|
round() |
In order to get the value of a number rounded to the nearest integer. |
|
sin() |
In order to get the sine of a number. |
|
sqrt() |
In order to get the square root of a number. |
|
tan() |
In order to get the tangent of a number. |
Code:
Math.sqrt() : It returns the square root of a number.
<html>
<body>
<h2>JavaScript Math Object</h2>
<script>
var x = Math.sqrt(49);
document.write("Square root of 49 is " +x);
</script>
</body>
</html>
Output:
Math.pow(a,b): It returns the value of a to the power of b.
<html>
<body>
<h2>JavaScript Math Object</h2>
<script>
var x = Math.pow(4,2);
document.write("4 to the power of 2 is " +x);
</script>
</body>
</html>
Output:

