JavaScript Reference

Overview
JS Reference

JS Array Object
JS Boolean Object
JS Date Object
JS Style Declaration Object
JS Error Object
JS Global Object
DOM Reference

DOM Attribute
DOM Console
DOM Document
DOM Element
DOM Events
DOM Event Objects
DOM History
DOM HTMLCollection
DOM Location
DOM Navigator
DOM Screen
DOM Style
DOM Window
WEB Storage
Math is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.

The Math object allows you to perform mathematical tasks on numbers.

Unlike the other global objects, Math is not a constructor.

All properties and methods of Math are static and can be called by using Math as an object, without creating it.

For example you refer to the constant pi as **Math.PI** and you call the sine function as **Math.sin(x)**, where x is the method's argument.

`var x = Math.PI; // Returns PI`

`var y = Math.sqrt(25); // Returns the square root of 25`

You can learn more about Math in our JavaScript Math Tutorial.

The following table lists the properties of the Math object:

Property | Description |
---|---|

E | Returns Euler's number, the base of natural logarithms, e, approximately 2.718 |

LN2 | Returns the natural logarithm of 2, approximately 0.693 |

LN10 | Returns the natural logarithm of 10, approximately 2.302 |

LOG2E | Returns the base 2 logarithm of e, approximately 1.442 |

LOG10E | Returns the base 10 logarithm of e, approximately 0.434 |

PI | Returns PI, approximately 3.14 |

SQRT1_2 | Returns the square root of 1/2, approximately 0.707 |

SQRT2 | Returns the square root of 2, approximately 1.414 |

The following table lists the methods of the Math object:

Method | Description |
---|---|

abs(x) | Returns the absolute value of x |

acos(x) | Returns the arccosine of x, in radians |

acosh(x) | Returns the hyperbolic arccosine of x |

asin(x) | Returns the arcsine of x, in radians |

asinh(x) | Returns the hyperbolic arcsine of x |

atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |

atan2(y, x) | Returns the arctangent of the quotient of its arguments |

atanh(x) | Returns the hyperbolic arctangent of x |

cbrt(x) | Returns the cubic root of x |

ceil(x) | Returns the smallest integer greater than or equal to a number |

cos(x) | Returns the cosine of x (x is in radians) |

cosh(x) | Returns the hyperbolic cosine of x |

exp(x) | Returns the value of E^{x} |

floor(x) | Returns the largest integer less than or equal to a number |

log(x) | Returns the natural logarithm (base E) of x |

max(n1, n2, n3, ..., nX) | Returns the number with the highest value |

min(n1, n2, n3, ..., nX) | Returns the number with the lowest value |

pow(x, y) | Returns the value of x to the power of y |

random() | Returns a random number between 0 and 1 |

round(x) | Rounds x to the nearest integer |

sin(x) | Returns the sine of x (x is in radians) |

sinh(x) | Returns the hyperbolic sine of x |

sqrt(x) | Returns the square root of x |

tan(x) | Returns the tangent of an angle |

tanh(x) | Returns the hyperbolic tangent of a number |

trunc(x) | Returns the integer part of a number (x) |

**Note:** The trigonometric functions (sin(), cos(), tan(), asin(), acos(), atan(), atan2()) expect or return angles in radians.

To convert radians to degrees, divide by (Math.PI / 180), and multiply by this to convert the other way.