更多"Try it Yourself"下面的例子。
定義和用法
的sqrt()方法返回一個數的平方根。
瀏覽器支持
方法 | |||||
---|---|---|---|---|---|
sqrt() | 是 | 是 | 是 | 是 | 是 |
句法
Math.sqrt( x )
參數值
參數 | 描述 |
---|---|
x | 需要。 一個號碼 |
技術細節
返回值: | 一個號碼。 如果x為負數,則返回NaN |
---|---|
JavaScript的版本: | 1.0 |

更多示例
例
返回不同數量的平方根:
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);
的結果,B,C,D和E將是:
0
1
3
8
NaN
試一試» <JavaScript的Math對象