Home JavaScript Math Methods cbrt() JavaScript Math.cbrt() Method Definition Math.cbrt(x) returns the cube root of a number. That is the number which, multiplied by itself three times, gives x. For example, the cube root of 27 is 3.
Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().
Syntax Call Math.cbrt() like this. Start with this line.
Call What it does Math.cbrt(x)Returns the cube root of x.
Built into JavaScript. Call Math.cbrt() on the Math object — no import required.
Library declarations interface Math {
cbrt(x: number): number;
} Parameters Parameter Description x Required. A number. Other values are converted to a number first.
Return Value Return Value Description number The cube root of x. Returns NaN if x cannot be turned into a number.
Important
Unlike a square root, a cube root works for negative numbers . Math.cbrt(-8) is -2, but Math.pow(-8, 1/3) is NaN.
JavaScript Examples 1. Basic use 2. Negative numbers 3. Side of a cube Example 1 — Basic Use Perfect cubes give whole numbers. Other numbers give decimals.
console.log(Math.cbrt(27)); // 3
console.log(Math.cbrt(1000)); // 10
console.log(Math.cbrt(2)); // 1.2599210498948732
console.log(Math.cbrt(0)); // 0 3
10
1.2599210498948732
0 How It Works Perfect cube. 3 * 3 * 3 is 27, so the cube root is 3.Another cube. 10 * 10 * 10 is 1000, so you get 10.Not a cube. 2 is not a perfect cube, so you get a decimal.Example 2 — Negative Numbers Math.cbrt() works for negative numbers. Math.pow(x, 1/3) does not.
console.log(Math.cbrt(-8)); // -2
console.log(Math.pow(-8, 1 / 3)); // NaN
console.log(Math.cbrt(-27)); // -3 How It Works Negative cube root. -2 * -2 * -2 is -8, so the cube root of -8 is -2.pow fails. Math.pow(-8, 1 / 3) returns NaN.Use cbrt. Choose Math.cbrt() when the number can be negative.Example 3 — Side of a Cube From Its Volume The volume of a cube is side * side * side. Use Math.cbrt() to go backwards.
function sideFromVolume(volume) {
return Math.cbrt(volume);
}
console.log(sideFromVolume(125)); // 5
console.log(sideFromVolume(64)); // 4
console.log(sideFromVolume(10).toFixed(2)); // 2.15 How It Works Volume in. A cube with volume 125 has sides of length 5.Another cube. Volume 64 means side 4.Not exact. For 10, round the answer with toFixed(2).Compatibility
Browser & Runtime Support Math.cbrt() is part of ES2015 and is Baseline Widely available in modern browsers and Node.js.
✓ Baseline · ES2015
Math.cbrt() Supported in Chrome, Firefox, Safari, Edge, and Node.js for years. Safe for modern apps without a polyfill.
98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support Math.cbrt Excellent
Bottom line: Use Math.cbrt() in new code. Only very old browsers, like Internet Explorer, lack it.
Frequently Asked Questions What does Math.cbrt() do? Math.cbrt(x) returns the cube root of x. Math.cbrt(27) is 3 and Math.cbrt(1000) is 10.
Can Math.cbrt() take a negative number? Yes. Math.cbrt(-8) is -2. A cube root of a negative number is negative.
Why not use Math.pow(x, 1/3)? Math.pow(-8, 1/3) returns NaN, and results can be slightly off. Math.cbrt() is simpler and more exact.
How is Math.cbrt() different from Math.sqrt()? sqrt finds the square root (multiply twice) and fails for negatives. cbrt finds the cube root (multiply three times) and works for negatives.
Which browsers support Math.cbrt()? It was added in ES2015 and works in all modern browsers and Node.js.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
11 people found this page helpful
Helpful Share Copy link Suggestion