JavaScript Math.cbrt(): Calculate Cube Root in JavaScript

JavaScript Math.cbrt(): real cube roots for positive and negative numbers, how cbrt differs from ** (1/3), and when to prefer Math.cbrt.

Published

Updated

Read time 2 min read

Reviewed byDeepak Prasad

JavaScript Math.cbrt(): Calculate Cube Root in JavaScript

JavaScript Math.cbrt() returns the cube root of a number. If you are searching for javascript cube root, js cube root, math cbrt, cbrt math, or what does cbrt mean in math, cbrt means cube root: the number that produces the input when multiplied by itself three times.

Environment: Node.js v20.18.2. Each snippet is plain JavaScript; the line after it states the expected console output.


Math.cbrt Syntax

Cube root curve valid for negative and positive real inputs unlike square root

javascript
Math.cbrt(x)
Output

Math.cbrt(x) returns the cube root of x. It works with positive numbers, negative numbers, zero, and values that can be converted to numbers.


Method 1: Calculate Cube Root with Math.cbrt()

javascript
console.log(Math.cbrt(27));
Output

You should see one line logging 3.

The cube root of 27 is 3 because 3 * 3 * 3 equals 27.


Method 2: Calculate Cube Root of Negative Numbers

Unlike square roots, cube roots can be negative.

javascript
console.log(Math.cbrt(-8));
Output

You should see one line logging -2.

The cube root of -8 is -2 because -2 * -2 * -2 equals -8.


Method 3: Handle Zero and Invalid Values

Math.cbrt() preserves negative zero.

javascript
console.log(Object.is(Math.cbrt(-0), -0));
Output

You should see one line logging true.

If the input cannot be converted to a number, the result is NaN.

javascript
console.log(Math.cbrt("hello"));
Output

You should see one line logging NaN.


Method 4: Use Math.cbrt() for Cube Volume

If a cube has volume 125, the side length is the cube root of 125.

javascript
const volume = 125;
const side = Math.cbrt(volume);

console.log(side);
Output

You should see one line logging 5.

This is cleaner than writing a fractional exponent and handles negative values correctly.


Common Questions About Math.cbrt

What is cbrt in math?

cbrt means cube root. It answers: what number multiplied by itself three times gives this value?

How do I calculate cube root in JavaScript?

Use Math.cbrt(number). For example, Math.cbrt(27) returns 3.

Does Math.cbrt work with negative numbers?

Yes. Math.cbrt(-8) returns -2.


Summary

Math.cbrt() handles negative inputs and -0 the way mathematicians expect—prefer it over Math.pow(x, 1/3) for clarity and edge cases.

JavaScript Math.cbrt() is the built-in method for calculating cube root. Use it for searches such as javascript cube root, js cube root, and math.cbrt javascript. It returns positive and negative cube roots correctly, preserves negative zero, and returns NaN for invalid numeric input.


Official Documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs …