JavaScript pow

The JavaScript pow function is a Math function used to calculate the Power of the specified expression. The syntax of the JavaScript pow Function is:

Math.pow(base, Exponent);
  • Base: Please specify the base value here.
  • Exponent: Please specify the Exponent value or power here.

For example, if x is base value and 2 is exponent then, Math.pow(x, 2) = x²


  • If the Base or Exponent value is not a number, the JavaScript pow function will return NaN.
  • If the Base or Exponent value is Null, it will return Zero.

JavaScript pow Function Example

The JavaScript pow function is used to return the Power of the given number. In this example, We are going to find the power of different data types and display the output.

First, we used the pow Function on both the Positive and negative decimal numbers. From the below screenshot, you can see the JavaScript power Function is returning NaN (Not a Number) as output for negative numbers.

Next, we used the Power Function on the string text for Str. The below JavaScript statement is converting the “3” to an integer.

For Str1, we used this math method on “String”, as we said before, it returns NaN as output.

Last, we used Null value as the second argument. Here, null converted to Zero.

<!DOCTYPE html>
    <title> JavaScriptPOWER Function </title>
  <h1> JavaScriptPOW Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Multi"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Str1"></p>
  <p id = "Null"></p>
    document.getElementById("Pos").innerHTML = Math.pow(2, 3);
    document.getElementById("Neg").innerHTML = Math.pow(-2, 3);
    document.getElementById("Multi").innerHTML = Math.pow(2, -3);
    document.getElementById("Dec").innerHTML = Math.pow(2.50, 4.05);
    document.getElementById("Neg_Dec").innerHTML = Math.pow(-3.10,-6.05);
    document.getElementById("Str").innerHTML = Math.pow(2, "3");
    document.getElementById("Str1").innerHTML = Math.pow(2, "String");
    document.getElementById("Null").innerHTML = Math.pow(4, null);
JavaScript POW Function