How to Use the Math.sqrt() Method in JavaScript



In this article, you will learn how to use the Math.sqrt() method in JavaScript.

The Math.sqrt() method

The Math.sqrt() method returns the square root of the number specified as an argument.

The syntax is below.


For example, to calculate the hypotenuse of a triangle, it is as follows.

 function calcHypotenuse(a, b) {
  return (Math.sqrt((a * a) + (b * b)));

console.log(calcHypotenuse(3, 4));
// expected output: 5