Math.cbrt()
Returns the cube root of a number.
Syntax
Math.cbrt(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | number | Yes | The number whose cube root is returned. |
Returns
number — The cube root of x.
Examples
console.log(Math.cbrt(27));
Output
3
console.log(Math.cbrt(-8));
Output
-2
Notes
Unlike `sqrt`, this works for negative numbers (cube root of -8 is -2). More
accurate than `Math.pow(x, 1/3)` for negatives.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 38 |
| firefox | 25 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |