Math is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
Unlike the other global objects,
Math is not a constructor. All properties and methods of
Math are static. You refer to the constant pi as
Math.PI and you call the sine function as
- Euler's constant and the base of natural logarithms, approximately 2.718.
- Natural logarithm of 2, approximately 0.693.
- Natural logarithm of 10, approximately 2.303.
- Base 2 logarithm of E, approximately 1.443.
- Base 10 logarithm of E, approximately 0.434.
- Ratio of the circumference of a circle to its diameter, approximately 3.14159.
- Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
- Square root of 2, approximately 1.414.
Note that the trigonometric functions (
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.
Note a lot of the math functions have a precision that's implementation-dependent. This means that different browsers can give a different result, and even the same JS engine on a different OS or architecture can give different results.
- Returns the absolute value of a number.
- Returns the arccosine of a number.
- Returns the arcsine of a number.
- Returns the arctangent of a number.
- Returns the arctangent of the quotient of its arguments.
- Returns the smallest integer greater than or equal to a number.
- Returns the cosine of a number.
- Returns Ex, where x is the argument, and E is Euler's constant (2.718…), the base of the natural logarithm.
- Returns the largest integer less than or equal to a number.
- Returns the natural logarithm (loge, also ln) of a number.
Math.max([x[, y[, …]]])
- Returns the largest of zero or more numbers.
Math.min([x[, y[, …]]])
- Returns the smallest of zero or more numbers.
- Returns base to the exponent power, that is,
- Returns a pseudo-random number between 0 and 1.
- Returns the value of a number rounded to the nearest integer.
- Returns the sine of a number.
- Returns the positive square root of a number.
- Returns the tangent of a number.
- Returns the string
Created by Mozilla Contributors, license: CC-BY-SA 2.5