In this post, we will learn how to find the square root of a number using JavaScript.
This program will take a number as an input from the user and calculate and print the square root of that number.
So, without further ado, let’s begin this tutorial.
JavaScript Program To Find The Square Root
var num = prompt("Enter a Number"); var root = Math.sqrt(num); // displays square root console.log("The Square Root of " + num + " is " + root);
Output
The Square Root of 49 is 7
How Does This Program Work ?
The Math.sqrt() function returns the square root of a number. If the value of the number is negative, then Math.sqrt() returns NaN.
Conclusion
I hope after going through this post, you understand how to find the square root of a number using JavaScript.
If you have any query regarding the program, feel free to contact us in the comment section. We will be delighted to help you.
Also Read: