JavaScript Math cbrt()

The cbrt() method computes the cube root of a specified number and returns it.

Example


cbrt() Syntax

The syntax of the Math.cbrt() method is:

Math.cbrt(number)

Here, cbrt() is a static method. Hence, we are accessing the method using the class name, Math.


cbrt() Parameter

The cbrt() method takes a single parameter:

  • number - value whose cube root is to be calculated

cbrt() Return Value

The cbrt() method returns:

  • the cube root of a given number
  • NaN (Not a Number) if the argument is non-numeric

Example 1: JavaScript Math.cbrt()

Here, we have used the Math.cbrt() method to compute the cube root of an integer value, 27 and a decimal value, 64.144.


Example 2: cbrt() with Numeric String

In the above example, the Math.cbrt() method converts the numeric string "125" into a number and then computes its cube root.


Example 3: Cube Root of String Argument

In the above example, we have tried to calculate the cube root of the string "Harry". That's why we get NaN as the output.


Recommended readings: