What is Math.cbrt() in JavaScript?
Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a cbrt() function, which is used to compute the cube root of a specified number.
Syntax
Math.cbrt(param);
Parameter
param: This is the input value of theNumbertype for which we want to find thecbrt().
Numberin JavaScript is a 64-bit double-precision value that is the same asdoublein C# or Java.
Return value
-
Number: It returns the cube root of the input parameterparam. It is of theNumbertype. -
Infinity: The function returns this if the input parameterparamisInfinity. -
NaN: The function returns this if the input parameterparamisNaN.
Example
console.log("cbrt(-8) = " + Math.cbrt(-8));console.log("cbrt(-1) = " + Math.cbrt(-1));console.log("cbrt(64) = " + Math.cbrt(64));console.log("cbrt(∞) = " + Math.cbrt(Infinity));console.log("cbrt(null) = " + Math.cbrt(null));console.log("cbrt(NaN) = " + Math.cbrt(NaN));