Math.cbrt() in JavaScript
The Math.cbrt() function is used to find the cube root of a number.
The cube root of a number is denoted as Math.cbrt(x)=y such that y^3=x.
Syntax:
Math.cbrt(number)
Parameters Used:
number:It is the number whose cuberoot you want to know.
Return Value:
It returns the cube root of the given number.
Examples:
Input : Math.cbrt(8) Output : 2 Input : Math.cbrt(-8) Output : -2 Input : Math.cbrt(0) Output : 0 Input : Math.cbrt(infinity) Output : Infinity
- When a positive number is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cbrt(8));
</
script
>
Output:
Output : 2
- When a negative number is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cbrt(-8));
</
script
>
Output:
Output : -2
- When zero is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cbrt(0));
</
script
>
Output:
Output : 0
- When infinity is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cbrt(infinity));
</
script
>
Output:
Output : Infinity