Skip to content

JavaScript square root | Program

  • by

A simple way to find the square root of a number use the Math sqrt() function in JavaScript. It is built-in takes a number as a parameter and returns its square root.


Note: The square root of the number is NaN if the number is Negative or String.

JavaScript square root

Simple example code.

<!DOCTYPE html>
   let a = Math.sqrt(0);
   let b = Math.sqrt(1);
   let c = Math.sqrt(9);
   let d = Math.sqrt(64);
   let e = Math.sqrt(-9); 


JavaScript square root Program

Find Square Root of a Number by user input number

// take the input from the user
const n= prompt('Enter the number: ');

const res = Math.sqrt(number);
console.log(`The square root of ${n} is ${res}`);


Enter the number: 9 
The square root of 9 is 3

Do comment if you have any doubts or suggestions on this JS Math sqrt() method topic.

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

Your email address will not be published. Required fields are marked *