totn JavaScript

JavaScript: Math cbrt() function

This JavaScript tutorial explains how to use the math function called cbrt() with syntax and examples.

Description

In JavaScript, cbrt() is a function that is used to return the cube root of a number. Because the cbrt() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the cbrt() function is:

Math.cbrt(number);

Parameters or Arguments

number
The number used to calculate the cube root.

Returns

The cbrt() function returns the cube root of a number.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which cbrt() is one of these functions.

Example

Let's take a look at an example of how to use the cbrt() function in JavaScript.

For example:

console.log(Math.cbrt(8));
console.log(Math.cbrt(27));
console.log(Math.cbrt(1000));

In this example, we have invoked the cbrt() function using the Math class.

We have written the output of the cbrt() function to the web browser console log, for demonstration purposes, to show what the cbrt() function returns.

The following will be output to the web browser console log:

2
3
10

In this example, the first output to the console log returned 2 which is the cube root of 8 (because 2 x 2 x 2 = 8).

The second output to the console log returned 3 which is the cube root of 27 (because 3 x 3 x 3 = 27).

The third output to the console log returned 10 which is the cube root of 1000 (because 10 x 10 x 10 = 1000).