English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Math.sqrt() Method

 JavaScript Math Object

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

If the passed parameter is negative, Math.sqrt() returns NaN.

Because sqrt() is a static method of Math, you should always use it asMath.sqrt(), rather than using it as a method of the created Math object.

Syntax:

Math.sqrt(x)
Math.sqrt(9);   // 3
Math.sqrt(64);  // 8
Math.sqrt(2);   // 1.414213562373095
Math.sqrt(1);   // 1
Math.sqrt(0);   // 0
Math.sqrt(-1);  // NaN
Test See‹/›

Browser Compatibility

All browsers fully support the Math.sqrt() method:

Method
Math.sqrt()YesYesYesYesYes

Parameter Value

ParameterDescription
xNumeric

Technical Details

Return Value:Square root of a given number. If the number is negative, it returnsNaN
JavaScript Version:ECMAScript 1

 JavaScript Math Object