How to use JavaScript Math.pow method

Posted on Jan 03, 2021

How to find the exponent of a number with JavaScript Math.pow method

In JavaScript, you can find the exponent value of a number by using the Math.pow() method, which accepts two parameters:

  • The first parameter is the base number
  • The second parameter is the exponent number to raise the base

Here’s an example of 4 to power 3 or 4*4*4:

let baseNumber = 4;
let exponentNumber = 3;
Math.pow(base, exponent);

// returns 64

When you pass only one parameter, the method will return NaN:


// returns NaN

You can calculate negative exponents, which will divide the base number instead of multiply it:

Math.pow(8, -2);

// returns 0.015625

When you pass 0 as the exponent number, the method will always return 1 as value:

Math.pow(7, 0);
Math.pow(0, 0);
Math.pow(0.7, 0);
Math.pow(-23, 0);
Math.pow(-3.2, 0);

// all returns 1

The method will return NaN for any negative base number to the power of fractional exponent:

Math.pow(-23, 0.7);

// returns NaN

When you pass any other data types, the method will return NaN as value:

Math.pow("hello", "world");

// returns NaN

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.