In this blog, we will learn the basic and most useful Math functions, available in JavaScript. These functions can be used for basic Math calculation.
- <script>
- //Math.abs()
- alert(Math.abs(-100.24)); //Returns Absolute value (value without negative
- or positive sign) of numbers.
- Output will be 100.24
- //Math.ceil()
- alert(Math.ceil(100.24)); //Rounds a number upwards to the nearest integer.
- Output will be 101
- //Math.floor()
- alert(Math.floor(100.85)); //Rounds a number downwards to the nearest integer.
- Output will be 100
- //Math.max()
- alert(Math.max(80, 100, 15, 75)); //Return the number with the highest value
- from the set of numbers.Output will be 100
- //Math.min()
- alert(Math.min(80, 100, 15, 75)); //Return the number with the lowest value
- from the set of numbers.Output will be 15
- //Math.pow()
- alert(Math.pow(5, 3)); //Returns value of first number to the power
- of second number(5 to the power of 3).
- Output will be 125
- //Math.random()
- alert(Math.random()); //Returns a random number between 0 and 1.
- //Math.round()
- alert(Math.round(100.50)); //Rounds a number to nearest integer.
- Output will be 101
- //Math.sqrt()
- alert(Math.sqrt(25)); //Returns Square root of a number.
- Output will be 5
- </script>

Join the conversation! Your thoughts help the community grow.