Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript sqrt() Method

JavaScript sqrt() Method

Math Object Reference JavaScript Math object

Example

Return the square root of a number:

Math.sqrt(9);

Output result:

3

Try it »


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 value

Parameters 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 roots 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, and LinkedHashMap, among others. e Output result:

0

1

3

8

NaN

Try it »


Math Object Reference JavaScript Math object