This tutorial is a part of our initiative at Flexiple, to write short curated tutorials around often used or interesting concepts.
Math.sqrt() function under the Math method, and since
sqrt() a static method of Math it must be used as
"#" - A number or an array storing a number.
The square root of the parameter. Sqrt() returns NaH in few cases we discuss later in the tutorial.
console.log(Math.sqrt(25)); // Output: 5 console.log(Math.sqrt(0.25)); //output: 0.5
Or in case you are looking to write it to your webpage:
<!DOCTYPE html> <html> <body> <p id=“squareroot”></p> <script> document.getElementById(“squareroot”).innerHTML = Math.sqrt(25); </script> </body> </html>
We are passing the value within the function and the square root is returned.
NaHis returned. A method to overcome this is to create a function that runs square root in the value individually and then return it