Math.cbrt()
Math.cbrt() 靜態方法返回一個數字的立方根。即
試一試
console.log(Math.cbrt(-1));
// Expected output: -1
console.log(Math.cbrt(1));
// Expected output: 1
console.log(Math.cbrt(Infinity));
// Expected output: Infinity
console.log(Math.cbrt(64));
// Expected output: 4
語法
js
Math.cbrt(x)
引數
x-
一個數字。
返回值
x 的立方根。
描述
因為 cbrt() 是 Math 的一個靜態方法,所以您總是透過 Math.cbrt() 來使用它,而不是透過您建立的 Math 物件的方法來使用(Math 不是建構函式)。
示例
使用 Math.cbrt()
js
Math.cbrt(-Infinity); // -Infinity
Math.cbrt(-1); // -1
Math.cbrt(-0); // -0
Math.cbrt(0); // 0
Math.cbrt(1); // 1
Math.cbrt(2); // 1.2599210498948732
Math.cbrt(Infinity); // Infinity
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-math.cbrt |
瀏覽器相容性
載入中…