Javascript has handy built-in objects. One of these popular built-in objects is the Math Object.
Number Constants
Here are some of the built-in number constants that exist on the Math object:
The Pi number:
Math.PI
, which is approximately 3.1459The Euler's constant:
Math.E
, approximately 2.718The natural Logarithm of 2:
Math.LN2
, approximately 0.693 in valueRounding methods
These include:
Math.ceil()
: rounds up to the closest integerMath.floor():
rounds down to the closest integerMath.round():
rounds up to the closest integer if the decimal is 0.5 or above, otherwise rounds down to the closest integerMath.trunc():
trims the decimal, leaving only the integerArithmetic and Calculus methods
Here is a non-conclusive list of some commonly used arithmetic and calculus methods that exist for the math object:
Math.pow(2,3)
: calculates the number 2 to the power 3, resulting in 8Math.sqrt(16):
calculates the square root of the number 16, resulting in 4Math.cbrt(27):
calculates the cube root of the number 27, resulting in 3Math.abs(-10)
: returns the absolute value(always positive), resulting in 10Logarithmic methods:
Math.log()
,Math.log2()
,Math.log10
()Return the minimum and maximum values of all the inputs:
Math.min(9,8,7)
returns 7,Math.max(9,8,7)
returns 9.Trigonometric methods:
Maths.sin()
,Maths.cos()
,Math.tan()
, etc
Thats all for this blog, hope it was worth your time. Thank you.