JavaScript sqrt()Method

Math 对象参考手册JavaScript Math Object

Example

Return the square root of a number:

Math.sqrt(9);

Output:

3

Try it Yourself »

Definition and Usage

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the sqrt() method


Syntax

Math.sqrt(x)

Parameter Values

Parameter Description
x Required. Must be a number greater than or equal to 0.

Return Value

Type Description
Number/NaN The square root of parameter x. If x is less than 0, NaN is returned.

Technical Details

JavaScript Version: 1.0


More Examples

Example

In this example, we will return the square root of different numbers:

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, andeOutput:

0
1
3
8
NaN

Try it Yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions