DEV Community

Pritom Deb
Pritom Deb

Posted on • Edited on

Important Math methods

1. Math.min(value0, value1, ... , valueN)
The Math.min( ) method is used to find the lowest value in a list of arguments. Have a look at the example below:
Image description

2. Math.max(value0, value1, /* ... ,*/ valueN)
The Math.max( ) method is used to find the highest value in a list of arguments. Have a look at the example below:
Image description

3. Math.round(a number value)
The Math.round(x) method returns the value of a number x rounded to its nearest integer:
Image description

4. Math.sqrt(a number value)
The Math.sqrt(x) is used to return the square root of a number x. If the value of x is negative, Math.sqrt() returns NaN. Have a look at the example below:
Image description

5. Math.pow(base, exponent)
The Math.pow(x, y) returns the value of x to the power of y. If the base is negative and the exponent is not an integer, the result is NaN. Let’s have a look at the below example:
Image description

6. Math.floor(a number value)
The Math.floor(x) returns the value of x rounded down to its nearest integer. Math.floor(null) returns 0, not a NaN.
Image description

7. Math.random( )
The Math.random() returns a random number between 0 and 1. It’s often used to extract random elements from an array.
Image description

8. Math.ceil(a number value)
The Math.ceil(x) returns the value of x rounded up to its nearest integer:
Image description

Top comments (2)

Collapse
 
devfranpr profile image
DevFranPR

Is pow still relevant since the aproval of ** operator?

Collapse
 
pritomdbhaskar profile image
Pritom Deb

Both works exactly the same. The only difference exponentiation operator doesn't work on older browser where pow() works in older browser. And you also need node version 7 or upper for exponentiation operator to work.