In JavaScript, you can use the Math.sqrt() function to calculate the square root of a number. Here’s an example:

let number = 16;
let squareRoot = Math.sqrt(number);
console.log(squareRoot); // Output: 4

You can also use the ‘**’ operator (ECMAScript 2016)

let number = 16;
let squareRoot = number ** 0.5;
console.log(squareRoot); // Output: 4

Note that the Math.sqrt() function only works with non-negative numbers. If you pass a negative number to the function, it will return ‘NaN’.

Also Read:

Categorized in: