
The JavaScript Math.sqrt() returns the square root of a number.
Syntax:
Math.sqrt(number)
Note: If a number is negative , NaN is returned.
Example:
<!DOCTYPE html>
<html>
<body>
<p id="example"></p>
<script>
let a = Math.sqrt(0);
let b = Math.sqrt(1);
let c = Math.sqrt(7);
let d = Math.sqrt(45);
let e = Math.sqrt(-9);
document.getElementById("example").innerHTML =
a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e;
</script>
</body>
</html>
Output:
The JavaScript Math.sqrt() returns the square root of a number:
Enjoy coding!
Read also: