Logical Interview Questions and Answers in JavaScript : Exponent power of a number
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:
- By using of default method: Math.pow ().
- By Looping: for loop and while loop.
- Recursive method.
Math.pow( ):
Math.pow() has two parameters:
- First is base digit
- 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.