JavaScript - Math.pow() Method
The JavaScript Math.pow() method returns the base raise to the power of exponent.
Syntax
Math.pow(base, exponent)
Parameters
base |
Specify the base. |
exponent |
Specify the exponent. |
Return Value
Returns the base raise to the power of exponent.
If the base is negative and the exponent is not an integer, the result is NaN.
Example:
In the example below, Math.pow() method is used to calculate the base raised to the power of exponent.
var txt; txt = "Math.pow(5, 2) = " + Math.pow(5, 2) + "<br>"; txt = txt + "Math.pow(5, 2.5) = " + Math.pow(5, 2.5) + "<br>"; txt = txt + "Math.pow(5.5, 2.5) = " + Math.pow(5.5, 2.5) + "<br>"; txt = txt + "Math.pow(-5, 2) = " + Math.pow(-5, 2.) + "<br>"; txt = txt + "Math.pow(-5, 2.5) = " + Math.pow(-5, 2.5) + "<br>"; txt = txt + "Math.pow(-5.5, 2.5) = " + Math.pow(-5.5, 2.5) + "<br>";
The output (value of txt) after running above script will be:
Math.pow(5, 2) = 25 Math.pow(5, 2.5) = 55.90169943749474 Math.pow(5.5, 2.5) = 70.94253836732938 Math.pow(-5, 2) = 25 Math.pow(-5, 2.5) = NaN Math.pow(-5.5, 2.5) = NaN
❮ JavaScript - Math Object