Logical Interview Questions and Answers in JavaScript : Exponent power of a number

Vaibhav Sharma
2 min readMay 7, 2019

--

Exponent power of a number:

We get the power value of exponent over the base number by using three methods:

  1. By using of default method: Math.pow ().
  2. By Looping: for loop and while loop.
  3. Recursive method.

Math.pow( ):

Math.pow() has two parameters:

  1. First is base digit
  2. Second is exponent.

Both of the parameters must be a number.

By using of Loops:

In that section, we find the value of power by using of for loop. We run the loop to exp -1 and each time we multiply pow by base value. when you exit from the loop, you return the value which stored in pow.

Recursive Method :

In the recursive method, you call the power() method recursively until exponent equal to 0 and each call we decrement the exponent value by 1.

Code:

--

--