JavaScript Math object is used to perform mathematical operations on numbers. Math is an inbuilt object that works with numbers types but it does not work with BigInt.
Example: Below example will give you a brief idea of JavaScript math objects.
javascript
// Return PI value(3.141592653589793) console.log(Math.PI); |
Output: This will print the value of Pi on the console.
3.141592653589793
JavaScript Math object properties and methods in JavaScript are listed below:
JavaScript Math Properties: A JavaScript property is a member of an object that associates a key with a value, in the math object of JavaScript there is a single type of property that are the static properties no instance properties are there.
- Static Property: A static property is a property that has the same value for the entire class.
Static Properties |
Description |
Example |
---|---|---|
E | The exp is a mathematical constant having an approximate value equal to 2.718. | |
LN2 | Find the value of a natural log of 2. | |
LN10 | Find the value of a natural log of 10. | |
LOG2E | Find the value of base 2 logarithms of e, where e is approximately equal to1.442 | |
LOG10E | Find the value of base 10 logarithms of e, where e is approximately equal to 0.434. | |
PI | Find the value of Pi | |
SQRT1_2 | Find the value of the square root of 1/2, whose value is approximately 0.707106. | |
SQRT2 | Find the value of the square root of 2, whose value is approximately 1.4142 |
JavaScript Math Methods: JavaScript methods ar There are e actions that can be performed on objects. Only static methods are available in the math object of JavaScript.
- Static Method: If the method is called using the Math class itself then it is called a static method of Math class.
Static Methods |
Description |
Example |
---|---|---|
abs() | Return the absolute value of a number. | |
acos() | Return the arccosine of a number in radians. | |
acosh() | Return the hyperbolic arc-cosine of a number. | |
asin() | Return the arcsine of a number in radians | |
asinh() | Return the arctangent of a number in radians. | |
atan() | Return the arctangent of a number in radians. | |
atan2() | Return the arctangent of the quotient of its arguments. | |
atanh() | Return the hyperbolic arctangent of a number. | |
cbrt() | Find the cube root of a number. | |
ceil() | Passed as a parameter to its nearest integer in an Upward direction of Rounding. | |
clz32() | Stands for “Count Leading Zeroes 32”. | |
cos() | Return the cosine of a number. | |
cosh() | Calculate the value of the hyperbolic cosine of a number. | |
exp() | Return ex, where x is the argument, and e is Euler’s number. | |
expm1() | Get the value of ep-1, where p is any given number. | |
floor() | The number is passed as a parameter to its nearest integer in a Downward direction of rounding. | |
fround() | Find the nearest 32-bit single-precision float representation of a given Number. | |
hypot() | Calculate the square root of the sum of squares of numbers passed to it as arguments. | |
imul() | Calculate the result of the 32-bit multiplication of the two integers passed as parameters to it | |
log() | Return the natural logarithm (base e) of a number. | |
log1p() | Gives the value of the natural logarithm of 1 + p number. | |
log2() | Gives the value of base 2 logarithms of any number. | |
log10() | Gives the value of base 10 logarithms of any number. | |
max() | Return the largest of zero or more numbers. | |
min() | Return the lowest-valued number passed in the method. | |
pow() | The value of the number raised to some exponent. | |
random() | Return a floating-point pseudo-random number between range [0,1), 0 (inclusive), and 1 (exclusive). | |
round( ) | The number is passed as a parameter to its nearest integer. | |
sign( ) | Sign of a number, indicating whether the number specified is negative or positive. | |
sin() | Return the sine of a number. | |
sinh() | The root of the number is passed as a parameter to the function. | |
sqrt( ) | The root of the number is passed as a parameter to the function. | |
tan() | Return the tangent of a number. | |
tanh() | Calculate the value of the hyperbolic tangent of a number. | |
trunc() | Return the integer part of a floating-point number by removing the fractional digits. |