How to use different Math functions in JavaScript?

Math functions allow us to perform mathematical operations. We can use the Math object in JavaScript, which provides us with a set of built-in static methods. We can work with numbers and perform various computations using this Math object. Let’s scroll through a number of Math functions with examples on how to use them.

Math.min

The min function of the Math object, returns the minimum value from a collection of values passed in the function.

Math.min(6,8,-6,1,-6)
Output: -5

Math.max

The max function of the Math object, returns the maximum value from a collection of values passed in the function.

Math.max(6,8,-6,1,-6)
Output: 8

Math.abs

The abs function of the Math object, returns the absolute value of the value passed in the function.

Math.abs(-6)
Output: 6

Math.pow

The pow function of the Math object, returns the power of the value passed in the function.

Math.pow(2, 4)
Output: 2^4 = 16

Math.sqrt

The sqrt function of the Math object, returns the square root of the value passed in the function.

Math.sqrt(5)
Output: 25

Math.hypot

The hypot function of the Math object, calculates the hypotenuse of the two values passed in the function.

Math.hypot(3, 4)
Output: 5

Math.ceil

The ceil function of the Math object, calculates the nearest integer value for the one passed in the function.

Math.ceil(7.3)
Output: 7

Math.ceil

The ceil function of the Math object, rounds up the nearest integer value for the one passed in the function.

Math.ceil(7.3)
Output: 8

Math.floor

The floor function of the Math object, rounds down the nearest integer value for the one passed in the function.

Math.floor(7.3)
Output: 7

Math.round

The round function of the Math object, rounds to the nearest integer value for the one passed in the function.

Math.round(7.3)
Output: 7

Hope you enjoyed the tutorial and learned about some amazing Math computational functions! Stay tuned for more.