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

Web Dev
Sponsored links

In this article, I will introduce 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