JavaScript sqrt

The JavaScript sqrt function is a Math function used to find the square root of a specified expression or a specific number. The syntax of the JavaScript sqrt Function is:

  • If the number argument is a positive integer, it will return the square root of a given value.
  • If it is Negative or not a number, JavaScript Square root function will return NaN.
  • And if it is Null, it returns Zero.

JavaScript sqrt Function Example

The JavaScript sqrt function finds the square root of a given number. In this example, we are going to find the JavaScript square root of different data types and display the output

<!DOCTYPE html>
    <title> JavaScriptSQRTFunction </title>
  <h1> JavaScriptSQRTFunction </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Null"></p>
    document.getElementById("Pos").innerHTML = Math.sqrt(10);
    document.getElementById("Neg").innerHTML = Math.sqrt(-10);
    document.getElementById("Dec").innerHTML = Math.sqrt(14.05);
    document.getElementById("Neg_Dec").innerHTML = Math.sqrt(-6.05);
    document.getElementById("Str").innerHTML = Math.sqrt("JavaScript");
    document.getElementById("Null").innerHTML = Math.sqrt(null);


  1. First two statements, We used the SQRT Function directly on the Positive and negative integer. From the below screenshot, you can see it is returning NaN as output for negative integer
  2. Following four statements, we used the JavaScript sqrt Function on the Positive and negative Decimal values. As we said before, it is returning NaN for negative decimal.
  3. Using this Function on the string value and this also returns NaN
  4. Last, We tried Js SQRT Math function on Null value, and it returns Zero as output
JavaScript SQRT Function