English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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); // NaNTest See‹/›
All browsers fully support the Math.sqrt() method:
Method | |||||
Math.sqrt() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
x | Numeric |
Return Value: | Square root of a given number. If the number is negative, it returnsNaN |
---|---|
JavaScript Version: | ECMAScript 1 |