Favorites

JavaScript Math.sqrt() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.sqrt()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Math.sqrt() static method returns the square root of a number.

Description

The Math.sqrt() static method returns the square root of a number. Negative numbers return NaN. It's the same as x ** 0.5.

Math.sqrt(-0) returns -0, and numbers that aren't perfect squares produce floating point results such as 1.4142135623730951 for 2. Math.SQRT2 and Math.SQRT1_2 are built-in constants for the square roots of 2 and one-half.

Square roots are used for distances, areas, standard deviations and normalizing vectors. For the distance between two points, Math.hypot() combines the squaring, adding and square root in one call. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.

Syntax

Math.sqrt(x)

Parameters

  • xA number, 0 or greater.

Return Value

The square root of x, or NaN if it is negative.

Example

console.log(Math.sqrt(81));
console.log(Math.sqrt(2));
console.log(Math.sqrt(-1));

Browser Support

The following information will show you the current browser support for the Math.sqrt() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee