JavaScript Math.sqrt() | Find square root of a number

The JavaScript Math.sqrt() method is used when we need to find the square root value of a specified number. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

  <script>
    let num = 81;
    document.getElementById("xyz").innerHTML = Math.sqrt(num);
  </script>
   
</body>
</html>
Output

JavaScript Math.sqrt() Syntax

The syntax of Math.sqrt() method in JavaScript is:

Math.sqrt(x)

The parameter x is required, refers to a number.

The Math.sqrt() returns the square root of specified parameter, that is x. Otherwise returns NaN in case if the specified value (x) is not a number or a negative number. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

  <p id="myPara"></p>

  <script>
    document.getElementById("myPara").innerHTML = Math.sqrt("jobails.com");
  </script>
   
</body>
</html>
Output

JavaScript Online Test


« Previous Tutorial Next Tutorial »