Math merupakan objek built-in yang memiliki properti dan method untuk perhitungan konstan dan fungsi. bukan Fungsi Objek.


Tidak seperti global objects lain, Math bukanlah constructor. Semua properti dan method dari Math adalah static. 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. Constants are defined with the full precision of real numbers in JavaScript.


Euler's constant and the base of natural logarithms, approximately 2.718.
Math.LN2 (en-US)
Natural logarithm of 2, approximately 0.693.
Natural logarithm of 10, approximately 2.303.
Math.LOG2E (en-US)
Base 2 logarithm of E, approximately 1.443.
Math.LOG10E (en-US)
Base 10 logarithm of E, approximately 0.434.
Math.PI (en-US)
Ratio of the circumference of a circle to its diameter, approximately 3.14159.
Math.SQRT1_2 (en-US)
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
Math.SQRT2 (en-US)
Square root of 2, approximately 1.414.


Note that 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.

Note that 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.
Math.acos(x) (en-US)
Returns the arccosine of a number.
Math.acosh(x) (en-US)
Returns the hyperbolic arccosine of a number.
Math.asin(x) (en-US)
Returns the arcsine of a number.
Math.asinh(x) (en-US)
Returns the hyperbolic arcsine of a number.
Math.atan(x) (en-US)
Returns the arctangent of a number.
Math.atanh(x) (en-US)
Returns the hyperbolic arctangent of a number.
Math.atan2(y, x) (en-US)
Returns the arctangent of the quotient of its arguments.
Math.cbrt(x) (en-US)
Returns the cube root of a number.
Returns the smallest integer greater than or equal to a number.
Math.clz32(x) (en-US)
Returns the number of leading zeroes of a 32-bit integer.
Math.cos(x) (en-US)
Returns the cosine of a number.
Math.cosh(x) (en-US)
Returns the hyperbolic cosine of a number.
Math.exp(x) (en-US)
Returns Ex, where x is the argument, and E is Euler's constant (2.718…), the base of the natural logarithm.
Math.expm1(x) (en-US)
Returns subtracting 1 from exp(x).
Returns the largest integer less than or equal to a number.
Math.fround(x) (en-US)
Returns the nearest single precision float representation of a number.
Math.hypot([x[, y[, …]]]) (en-US)
Returns the square root of the sum of squares of its arguments.
Math.imul(x, y) (en-US)
Returns the result of a 32-bit integer multiplication.
Math.log(x) (en-US)
Returns the natural logarithm (loge, also ln) of a number.
Math.log1p(x) (en-US)
Returns the natural logarithm of 1 + x (loge, also ln) of a number.
Math.log10(x) (en-US)
Returns the base 10 logarithm of a number.
Math.log2(x) (en-US)
Returns the base 2 logarithm 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.
Math.pow(x, y)
Returns base to the exponent power, that is, baseexponent.
Math.random() (en-US)
Returns a pseudo-random number between 0 and 1.
Math.round(x) (en-US)
Returns the value of a number rounded to the nearest integer.
Math.sign(x) (en-US)
Returns the sign of the x, indicating whether x is positive, negative or zero.
Math.sin(x) (en-US)
Returns the sine of a number.
Math.sinh(x) (en-US)
Returns the hyperbolic sine of a number.
Math.sqrt(x) (en-US)
Returns the positive square root of a number.
Math.tan(x) (en-US)
Returns the tangent of a number.
Math.tanh(x) (en-US)
Returns the hyperbolic tangent of a number.
Math.toSource() This API has not been standardized.
Returns the string "Math".
Math.trunc(x) (en-US)
Returns the integral part of the number x, removing any fractional digits.


Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Math' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Math' in that specification.
Standard New methods log10() (en-US), log2() (en-US), log1p() (en-US), expm1() (en-US), cosh() (en-US), sinh() (en-US), tanh() (en-US), acosh() (en-US), asinh() (en-US), atanh() (en-US), hypot() (en-US), trunc() (en-US), sign() (en-US), imul() (en-US), fround() (en-US), cbrt() (en-US) and clz32() (en-US) added.
ECMAScript (ECMA-262)
The definition of 'Math' in that specification.
Living Standard  

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also