JavaScript · JS Tutorial · Lesson 24
JS Math
Math.round, floor, ceil, max, min, pow and sqrt.
The Math object lets you perform mathematical tasks. It has no constructor — methods are called directly.
Example
<p id="demo"></p>
<script>
let out = "";
out += "PI: " + Math.PI + "<br>";
out += "round(4.6): " + Math.round(4.6) + "<br>";
out += "floor(4.7): " + Math.floor(4.7) + "<br>";
out += "ceil(4.1): " + Math.ceil(4.1) + "<br>";
out += "trunc(-4.7): " + Math.trunc(-4.7) + "<br>";
out += "pow(8, 2): " + Math.pow(8, 2) + "<br>";
out += "sqrt(64): " + Math.sqrt(64) + "<br>";
out += "max(0, 150, 30): " + Math.max(0, 150, 30) + "<br>";
out += "abs(-7.25): " + Math.abs(-7.25);
document.getElementById("demo").innerHTML = out;
</script>
Keep reading “JS Math”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.