basic

Math.cbrt

Returns the cube root of a number. Introduced in ES2015, and unlike sqrt it handles negative inputs correctly.

Math.cbrt(x)

Parameters & edge cases

Case Behavior
x Any number; negatives are supported
negative input Math.cbrt(-8) === -2, unlike Math.pow(-8, 1/3) which returns NaN
ES2015+ Not in older browsers; polyfill via a signed pow trick if needed

Examples

console.log(Math.cbrt(27));   // 3

3 cubed is 27.

console.log(Math.cbrt(-8));   // -2

Handles negatives — a big win over Math.pow(-8, 1/3).

console.log(Math.cbrt(0));    // 0

Zero returns zero.

console.log(Math.cbrt(2));    // 1.2599210498948732

Irrational cube root of 2.

Gotcha

Math.pow(-8, 1/3) is NaN because 1/3 is not exactly representable; always use Math.cbrt for signed cube roots.

Related

← All JS Math methods · Array methods