JavaScript CBRT

The JavaScript CBRT function is one of the Math functions and it is used to find the cube root of a specified expression or an individual number. The basic syntax of the JavaScript CBRT Function is:

Math.cbrt(number);

Number: It can be a number or a valid numerical expression.

  • If the number argument is positive or Negative number, CBRT() function will return the cube root of a given value.
  • If the number argument is not a number, CBRT() function will return NaN.
  • When the number argument is Null, CBRT() function will return Zero.

JavaScript CBRT Function Example

The JavaScript CBRT function is used to find the cube root of a given number. In this example, We are going to find the cube root of different data types and display the output

  1. First two statements, We used the CBRT Function directly on both the Positive integer and negative integer. From the below screenshot you can observe that, the CBRT() Function is returning the cube roots.
  2. Next two statements, We used the JavaScript CBRT Function on both the Positive and negative Decimal values this Function is working fine with decimal values as well.
  3. Next statement, We tried CBRT Math function on String value. As we said before, this will return NaN (Not a Number) as output
  4. Last, We tried CBRT() Function on Null value and it return Zero as output
<!DOCTYPE html>
<html>
<head>
    <title> JavaScript CBRT Function </title>
</head>
<body>
  <h1> JavaScript CBRT Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Null"></p>
  <script>
    document.getElementById("Pos").innerHTML = Math.cbrt(10);
    document.getElementById("Neg").innerHTML = Math.cbrt(-10);
    document.getElementById("Dec").innerHTML = Math.cbrt(14.05);
    document.getElementById("Neg_Dec").innerHTML = Math.cbrt(-6.05);
    document.getElementById("Str").innerHTML = Math.cbrt("JavaScript");
    document.getElementById("Null").innerHTML = Math.cbrt(null);
  </script>
</body>
</html>
JavaScript CBRT Function

Comments are closed.