This is a basic exponent function using recursive way. I do understand how recursive works but I am having trouble seeing how this returns the base by returning the function itself
function exponent(b,n){
if(n == 0){
return 1;
}else if(n == 1){
return b;
}
return exponent(b,n-1);
// return b*exponent(b,n-1);
}
console.log(exponent(7,2)); //7
I commented out the real output because I was trying to see what exponent(b,n-1)
means and I don't really understand is how does returning exponent(b,n-1)
will give out the base as the result?