Math.cbrt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phương thức tĩnh Math.cbrt() trả về căn bậc ba của một số. Cụ thể:

𝙼𝚊𝚝𝚑.𝚌𝚋𝚛𝚝(𝚡)=x3=the unique y such that y3=x\mathtt{\operatorname{Math.cbrt}(x)} = \sqrt[3]{x} = \text{the unique } y \text{ such that } y^3 = x

Try it

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

Cú pháp

js
Math.cbrt(x)

Tham số

x

Một số.

Giá trị trả về

Căn bậc ba của x.

Mô tả

cbrt() là một phương thức tĩnh của Math, bạn luôn sử dụng nó dưới dạng Math.cbrt(), thay vì là phương thức của một đối tượng Math bạn tạo ra (Math không phải là constructor).

Ví dụ

Sử dụng 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

Đặc tả kỹ thuật

Thông số kỹ thuật
ECMAScript® 2027 Language Specification
# sec-math.cbrt

Tương thích trình duyệt

Xem thêm