English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Math is a built-in object that has properties and methods for mathematical constants and functions. It is not a function object.
The Math object allows you to perform mathematical tasks on numbers.
Unlike other global objects, Math is not a constructor.
All properties and methods of Math are static and can be called as an object without creating it.
For example, call the constant piMath.PI, call the sine functionMath.sin(x), where x is the parameter of the method.
var x = Math.PI; // Return PI var y = Math.sqrt(25);// Return25square roottest to see‹/›
You can test on ourIn the JavaScript Math tutorialTo learn more about Math.
The following table lists the properties of the Math object:
Properties | Description |
---|---|
E | Return Euler's number, the base e of the natural logarithm, approximately2.718 |
LN2 | Return2natural logarithm, approximately 0.693 |
LN10 | Return the natural logarithm10, about2.302 |
LOG2E | Return e to the power of2logarithm to the base e, approximately1.442 |
LOG10E | Return e to the power of10logarithm to the base e, approximately 0.434 |
PI | Return PI, approximately3.14 |
SQRT1_2 | Return1/2square root, approximately 0.707 |
SQRT2 | Return2The square root, approximately1.414 |
The following table lists the methods of the Math object:
Method | Description |
---|---|
abs(x) | Return the absolute value of x |
acos(x) | Return the arccosine of x, in radians |
acosh(x) | Return the hyperbolic arccosine value of x |
asin(x) | Return the radians of x |
asinh(x) | Return the hyperbolic arcsine value of x |
atan(x) | Return the arctangent value of x as-PI / 2and PI / 2the numerical value between |
atan2(y, x) | Return the arctangent value of the quotient of its parameters |
atanh(x) | Return the hyperbolic arctangent of x |
cbrt(x) | Return the cube root of x |
ceil(x) | Return the smallest integer greater than or equal to x |
cos(x) | Return the cosine of x (x is represented in radians) |
cosh(x) | Return the hyperbolic cosine value of x |
exp(x) | Return E xvalue |
floor(x) | Return the largest integer less than or equal to x |
log(x) | log(x) |
Returns the natural logarithm of x (base E)1, n2, n3, ..., nX) | max(n |
Returns the largest number1, n2, n3, ..., nX) | Returns the smallest number |
pow(x, y) | Returns x to the power of y |
random() | Returns a random number between 0 to1to a random number between |
round(x) | Rounds x to the nearest integer |
sin(x) | Returns the sine of x (x is represented in radians) |
sinh(x) | Returns the hyperbolic sine value of x |
sqrt(x) | Returns the square root of x |
tan(x) | Returns the tangent of the angle |
tanh(x) | Returns the hyperbolic tangent of the number |
trunc(x) | Returns the integer part of the number (x) |
Note:Trigonometric Functions (sin(), cos(), tan(), asin(), acos(), atan(), atan2()) to represent the expected angle or return angle in radians.
To convert radians to degrees, divide by (Math.PI / 180), then multiply this value to perform another conversion.