Skip to content

JavaScript square root of Number | Example code

  • by

Use the Math sqrt() function to the square root of a Number in JavaScript. This function returns the square root of a number.

Math.sqrt(x)

Note: The square root of the negative number is NaN returned. And If a string is passed, NaN is returned.

Example get square root in JavaScript

A simple example code gets the square root of 9.

<!DOCTYPE html>
<html>
<head>

  <script>
    let x = Math.sqrt(9);

    console.log(x); 
  </script>
</head>
<body>

</body>
</html>

Output:

JavaScript square root of Number

More example

Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095

Math.sqrt(1);  // 1
Math.sqrt(0);  // 0
Math.sqrt(-1); // NaN
Math.sqrt(-0); // -0

Do comment if you have any doubts or suggestions on this JS mathematical operation code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading