此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Math.cbrt()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

Math.cbrt() 函数返回任意数字的立方根。

语法

Math.cbrt(x)

参数

x

任意数字。

返回值

给定数字的立方根

描述

该方法为 Math 的静态方法,因此请直接通过 Math.cbrt() 方式调用。

而不是作为你创建的 Math 对象的方法 (Math 不是构造函数)。

cbrt 是 "cube root" 的缩写,意思是立方根。

示例

使用 Math.cbrt()

js
Math.cbrt(NaN); // NaN
Math.cbrt(-1); // -1
Math.cbrt(-0); // -0
Math.cbrt(-Infinity); // -Infinity
Math.cbrt(0); // 0
Math.cbrt(1); // 1
Math.cbrt(Infinity); // Infinity
Math.cbrt(null); // 0
Math.cbrt(2); // 1.2599210498948732

规范

规范
ECMAScript® 2027 Language Specification
# sec-math.cbrt

浏览器兼容性

参见