Skip to content

JavaScript Square Root Example

Ramesh Fadatare edited this page Aug 11, 2020 · 1 revision

In this source code example, you'll learn to write a program to find the square root of a number in JavaScript.

To find the square root of a number in JavaScript, you can use the built-in Math.sqrt() method.

JavaScript Square Root Example

function findSqaureRoot(number){
	return Math.sqrt(number);	
}

let number1 = 9;
let number2 = 16;

let result1 = findSqaureRoot(number1);
let result2 = findSqaureRoot(number2);

console.log(`The square root of ${number1} is ${result1}`);
console.log(`The square root of ${number2} is ${result2}`);

Output

The square root of 9 is 3
The square root of 16 is 4
Clone this wiki locally