JavaScript sqrt()Method
Definition and Usage
The sqrt() method returns the square root of a number.
Browser Support
![]()
![]()
![]()
![]()
![]()
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);
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
1
3
8
NaN
Try it Yourself »
Other Extensions
JavaScript Math Object