Home >>JavaScript Math Reference >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 | Description |
---|---|
x | It required a Number |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
sqrt() | Yes | Yes | Yes | Yes | Yes |
<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>
<html> <body> <script> document.write(Math.sqrt(-4) + "<br>"); document.write(Math.sqrt(-4.66)); </script> </body> </html>