JavaScript Math pow()

The JavaScript Math.pow() function returns a number raised to a certain power.

It returns the base to the exponent power, i.e. baseexponent.

The syntax of the Math.pow() function is:

Math.pow(base, exponent)

pow(), being a static method, is called using the Math class name.


Math.pow() Parameters

The Math.pow() function takes in:

  • base - The base number
  • exponent - The exponent that is used to raise the base

Return value from Math.pow()

  • Returns Number that equals to the base raised to the exponent power.

Example: Using Math.pow()

// using Math.pow()

// simple numbers
var num = Math.pow(5, 2);
console.log(num); // 25

// fractional exponents
num = Math.pow(8, 1 / 3); // cube root
console.log(num); // 2

// signed base or exponents
num = Math.pow(-2, 5);
console.log(num); // -32

num = Math.pow(4, -2);
console.log(num); // 0.0625

// -ve bases with fractional exponents return NaN
num = Math.pow(-8, 1 / 3);
console.log(num); // NaN

Output

25
2
-32
0.0625
NaN

Here, we can see that the Math.pow() function returns the base raised to the exponent power. However, notice that negative bases with fractional exponents always return NaN.

Did you find this article helpful?