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.
  1. <script>
  2. //Math.abs()
  3. alert(Math.abs(-100.24)); //Returns Absolute value (value without negative
  4. or positive sign) of numbers.
  5. Output will be 100.24
  6. //Math.ceil()
  7. alert(Math.ceil(100.24)); //Rounds a number upwards to the nearest integer.
  8. Output will be 101
  9. //Math.floor()
  10. alert(Math.floor(100.85)); //Rounds a number downwards to the nearest integer.
  11. Output will be 100
  12. //Math.max()
  13. alert(Math.max(80, 100, 15, 75)); //Return the number with the highest value
  14. from the set of numbers.Output will be 100
  15. //Math.min()
  16. alert(Math.min(80, 100, 15, 75)); //Return the number with the lowest value
  17. from the set of numbers.Output will be 15
  18. //Math.pow()
  19. alert(Math.pow(5, 3)); //Returns value of first number to the power
  20. of second number(5 to the power of 3).
  21. Output will be 125
  22. //Math.random()
  23. alert(Math.random()); //Returns a random number between 0 and 1.
  24. //Math.round()
  25. alert(Math.round(100.50)); //Rounds a number to nearest integer.
  26. Output will be 101
  27. //Math.sqrt()
  28. alert(Math.sqrt(25)); //Returns Square root of a number.
  29. Output will be 5
  30. </script>
Hope, this will be helpful for someone out there.