Latest web development tutorials

JavaScript sqrt () method

Math Object Reference JavaScript Math Object

Examples

Returns the square root of a number:

Math.sqrt(9);

Output:

3

try it"

Definition and Usage

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support sqrt () method


grammar

Math.sqrt( x )

Parameter Value

参数 描述
x 必需。必须是大于等于 0 的数。

return value

类型 描述
Number/NaN 参数 x 的平方根。如果 x 小于 0,则返回 NaN。

technical details

JavaScript version: 1.0


More examples

Examples

In this case, we will return to the square root of the different figures:

var a=Math.sqrt(0);
var b=Math.sqrt(1);
var c=Math.sqrt(9);
var d=Math.sqrt(64);
var e=Math.sqrt(-9);

a, b, c, d, and e output:

0
1
3
8
NaN

try it"


Math Object Reference JavaScript Math Object