Attributes of Math
Several attributes of Math are several commonly used values in mathematics:
E : Returns the constant e (2.718281828...).
LN2 : Returns the natural logarithm of 2 (ln 2).
LN10 : Returns the natural logarithm of 10 (ln 10).
LOG2E : Returns the logarithm of e with 2 as the low value (log2e).
LOG10E : Returns the logarithm of e with 10 as the low (log10e).
PI : Return π (3.1415926535...).
SQRT1_2: Returns the square root of 1/2.
SQRT2: Returns the square root of 2.
Methods of Math
The built-in methods of Math are some commonly used mathematical operations in mathematics:
abs(x) : Returns the absolute value of x.
round(x): Returns the rounded value of x.
sqrt(x): Returns the square root of x.
ceil(x) : Returns the smallest integer greater than or equal to x.
floor(x): Returns the largest integer less than or equal to x.
sin(x): Returns the sine of x.
cos(x): Returns the cosine of x.
tan(x) : Returns the tangent of x.
acos(x) : Returns the inverse cosine of x (the cosine is equal to the angle of x), expressed in radians.
asin(x): Returns the arcsine of x.
atan(x): Returns the arctangent of x.
exp(x) : Returns e raised to the x power (e^x).
pow(n, m) : Returns n raised to the m power (nm).
log(x) : Returns the natural logarithm of x (ln x).
max(a, b): Returns the larger number between a and b.
min(a, b): Returns the smaller number between a and b.
random() : Returns a random number greater than 0 and less than 1.
The Math object is an inherent object. There is no need to create it. You can call all its properties and methods by directly using Math as an object. This is its difference from Date and String objects.
Next Section