How to use JavaScript Math.pow method

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

Posted on January 03, 2021

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

Related articles:

Grab the free JavaScript book today 👍

Learn the building blocks of JavaScript programming language like data types, functions, objects, arrays and classes.

Use the knowledge from the book to build a small but solid program.

Learn more