Home >>JavaScript Math Reference >JavaScript sqrt() Method

JavaScript sqrt() Method

JavaScript sqrt() Method

The Math.sqrt() method in JavaScript is a static method and is used to returns the square root of a number passed to parameter. If the parameter passed to a parameter is negative, it returns NaN. You always use it Math.sqrt(), rather than a method of a object.

Syntax:
Math.sqrt(value)

Parameter Values

Parameter Description
x It required a Number

Browser Support

Method Chrome Edge Firefox Safari Opera
sqrt() Yes Yes Yes Yes Yes
Here is an example of JavaScript sqrt() Method:
<html>
<body>
<button onclick="mySqrt()">Click me</button>
<p id="sqrt"></p>
<script>
function mySqrt() 
{
  document.getElementById("sqrt").innerHTML = Math.sqrt(12);
}
</script>
</body>
</html>
Output:

Example 2:
<html>
<body>
<script> 
  document.write(Math.sqrt(-4) + "<br>");
  document.write(Math.sqrt(-4.66));		 
</script> 
</body>
</html>
Output:

No Sidebar ads