Javascript Math Object

A JavaScript Math object provides no. of properties and methods for performing mathematical operations. Math is not a constructor and all the properties and methods of Math are static.

Example:

<script>
var num = Math.random();
var squarRoot = Math.sqrt(num ) ;
document.write("Random Number: " + num + "</br>");
document.write("Square root: " + squarRoot );
</script>

JavaScript Math Object Properties:

Property Description
E \ Euler’s constant and the base of natural logarithms, approximately 2.718.
LN2 Natural logarithm of 2, approximately 0.693.
LN10 Natural logarithm of 10, approximately 2.302.
LOG2E Base 2 logarithm of E, approximately 1.442.
LOG10E Base 10 logarithm of E, approximately 0.434.
PI The ratio of the circumference of a circle to its diameter is approximately 3.14159.
SQRT1_2 The square root of 1/2; equivalently, 1 over the square root of 2, is approximately 0.707.
SQRT2 The square root of 2, is approximately 1.414.

JavaScript Math Object Methods:

abs() method:
Use: To get the absolute value of the given number.
acos() method:
Use: To get the arccosine of the given number in radians.
asin() method:
Use: To get the arcsine of the given number in radians.
atan() method:
Use: To get the arc-tangent of the given number in radians.
cbrt() method:
Use: To get the cube root of the given number.
ceil() method:
Use: To get the smallest integer value, greater than or equal to the given number.
cos() method:
Use: To get the cosine of the given number.
cosh() method:
Use: To get the hyperbolic cosine of the given number.
exp() method:
Use: To get the exponential form of the given number.
floor() method:
Use: To get the largest integer value, lower than or equal to the given number.
hypot() method:
Use: To get the square root of the sum of the squares of given numbers.
log() method:
Use: To get the natural logarithm of a number.
max() method:
Use: To get the maximum value of the given numbers.
min() method:
Use: To get the minimum value of the given numbers.
pow() method:
Use: To get the value of base to the power of exponent.
random() method:
Use: To get a random number between 0 (included) and 1 (excluded).
round() method:
Use: To get the closest integer value of the given number.
sign() method:
Use: To get the sign of the given number.
sin() method:
Use: To get the sine of the given number.
sinh() method:
Use: To get the hyperbolic sine of the given number.
sqrt() method:
Use: To get the square root of the given number.
tan() method:
Use: To get the tangent of the given number.
tanh() method:
Use: To get the hyperbolic tangent of the given number.
trunc() method:
Use: To get the integer part of the given number.