Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Math

Math.cbrt()

Reference for Math.cbrt(): computing cube roots of positive and negative numbers, how it differs from ** (1/3), exact results and precision notes.

Math.cbrt() returns the cube root of a number: the value that, multiplied by itself three times, gives the argument. Math.cbrt(27) is 3 and Math.cbrt(-8) is -2.

Unlike the square root, a cube root exists for negative numbers, so Math.cbrt() returns a real result for any finite input. That is its main advantage over x ** (1 / 3), which gives NaN for a negative base.

JavaScript
Math.cbrt(x)

Try it

JS Cube roots

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS cbrt versus ** (1/3)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Math.cbrt(x)
Name Description
x A number (or a value that converts to one).

Return value: the cube root of x. The sign of x is preserved, -0 stays -0, and Infinity and -Infinity map to themselves. Non-numeric input gives NaN.

Exceptions: a BigInt argument throws a TypeError.

Usage notes

  • Works with negatives. Math.cbrt(-64) is -4. The expression (-64) ** (1 / 3) is NaN.
  • Exact for perfect cubes. Engines return exact answers for the common cases such as 8, 27 and 1000, which a floating-point ** (1 / 3) often misses because 1 / 3 is not exactly one third.
  • Irrational results like Math.cbrt(2) are, as always, approximations. Compare with a tolerance and round for display.
  • Perfect-cube test. Use Number.isInteger(Math.cbrt(n)) for modest integers; round the root and cube it again to be safer with larger values.
  • Other roots. For a fourth root and higher, use x ** (1 / n), remembering that negative bases give NaN. For odd roots of negative numbers, take the root of the absolute value and restore the sign yourself.
  • Related geometry: the diameter of a sphere from its volume needs a cube root, as does scaling 3D models uniformly.

Browser support

Part of ES2015 and supported in all current browsers.