JavaScript Math.cbrt()

Posted by

JavaScript Math.cbrt()

The Math.cbrt() function in JavaScript is used to calculate the cube root of a given number. It is a static function of the Math object and can be used without creating an instance of the Math object. It returns the cube root of the number passed into it as the argument. It is a part of the ECMAScript 6 (ES6) specification.

Syntax

The syntax of the Math.cbrt() function is as follows:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

Math.cbrt(num)

[/dm_code_snippet]

Here, num is the number for which the cube root needs to be calculated.

Return Value

The Math.cbrt() function returns the cube root of the number passed as the argument.

Example

Consider the following example to understand the use of Math.cbrt() function:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

let num = 8;
let cubeRoot = Math.cbrt(num);

console.log(cubeRoot); // 2

[/dm_code_snippet]

In the above example, the Math.cbrt() function is used to calculate the cube root of 8 which is 2.

Browser Support

The Math.cbrt() function is supported by all modern web browsers such as Chrome, Firefox, and Edge.