Math.sqrt()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheMath.sqrt() static method returns the square root of a number. That is
In this article
Try it
function calcHypotenuse(a, b) { return Math.sqrt(a * a + b * b);}console.log(calcHypotenuse(3, 4));// Expected output: 5console.log(calcHypotenuse(5, 12));// Expected output: 13console.log(calcHypotenuse(0, 0));// Expected output: 0Syntax
js
Math.sqrt(x)Parameters
xA number greater than or equal to 0.
Return value
The square root ofx, a nonnegative number. Ifx < 0, returnsNaN.
Description
Becausesqrt() is a static method ofMath, you always use it asMath.sqrt(), rather than as a method of aMath object you created (Math is not a constructor).
Examples
>Using Math.sqrt()
js
Math.sqrt(-1); // NaNMath.sqrt(-0); // -0Math.sqrt(0); // 0Math.sqrt(1); // 1Math.sqrt(2); // 1.414213562373095Math.sqrt(9); // 3Math.sqrt(Infinity); // InfinitySpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.sqrt> |