JavaScript Tutorial JavaScript References

JavaScript - Math Object



The JavaScript Math is a built-in object that has properties and methods for mathematical constants and functions. Unlike other global objects, Math is not a constructor. All the properties and methods of Math are static and can be called by using Math as an object without creating it. All functions and constants of Math object are listed below:

Math Object Methods

Trigonometric Methods

MethodsDescription
sin() Returns the trigonometric sine of an angle in radians.
cos() Returns the trigonometric cosine of an angle in radians.
tan() Returns the trigonometric tangent of an angle in radians.
asin() Returns the arc sine of a value.
acos() Returns the arc cosine of a value.
atan() Returns the arc tangent of a value.
atan2() Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).

Hyperbolic Methods

MethodsDescription
sinh() Returns the hyperbolic sine of a value.
cosh() Returns the hyperbolic cosine of a value.
tanh() Returns the hyperbolic tangent of a value.
asinh() Returns the inverse hyperbolic sine of a value
acosh() Returns the inverse hyperbolic cosine of a value
atanh() Returns the inverse hyperbolic tangent of a value

Exponential & Logarithmic Methods

MethodsDescription
exp() Returns the exponent of e.
expm1() Returns the exponent of e minus 1, i.e., ex-1.
log() Returns the natural logarithm of a given number.
log10() Returns the base-10 logarithm of a given number.
log1p() Returns the natural logarithm of (1+number), i.e., log(1+number).
log2() Returns the base-2 (binary) logarithm of a given number.

Rounding Methods

MethodsDescription
ceil() Rounds the given number up to the nearest integer.
floor() Rounds the given number down to the nearest integer.
trunc() Rounds the given number towards zero.
round() Rounds the given number to nearby integral value.

Power Methods

MethodsDescription
pow() Returns base raised to the power of exponent.
sqrt() Returns the square root of the given number.
cbrt() Returns the cube root of the given number.
hypot() Returns square root of sum of squares of two arguments, i.e., sqrt(x2 +y2).

Other Methods

MethodsDescription
abs() Returns the absolute (positive) value of the given number.
max() Returns the largest of zero or more numbers.
min() Returns the smallest of zero or more numbers.
sign() Returns the sign of the passed argument, indicating whether it is positive, negative, or zero.
fround() Returns the nearest single precision float representation of the passed argument.
imul() Returns the result of the C-like 32-bit multiplication of the two parameters.
random() Returns a pseudo-random number between 0 and 1.
clz32() Returns the number of leading zero bits of the 32-bit binary representation of a number.

Math Object Properties

PropertiesDescription
Math.E Euler's constant and the base of natural logarithms. It is approximately 2.718.
Math.LN2 Natural logarithm of 2; approximately 0.693.
Math.LN10 Natural logarithm of 10; approximately 2.303.
Math.LOG2E Base-2 logarithm of E; approximately 1.443.
Math.LOG10E Base-10 logarithm of E; approximately 0.434.
Math.PI Ratio of the a circle's circumference to its diameter. It is approximately 3.14159.
Math.SQRT1_2 Square root of ½; approximately 0.707.
Math.SQRT2 Square root of 2; approximately 1.414.