Can someone please explain this recursive JS code to calculate exponents?
问题 I can't understand this recursion even though it's a really simple example. When it goes to power(base, exponent - 1); what is that supposed to do? How are things being multiplied when power keeps getting invoked until exponent equals 0? function power(base, exponent) { if (exponent === 0) { return 1; } else { return base * power(base, exponent - 1); } } 回答1: Let's start from the beginning. Let's say you call power(base, 0) . Since exponent is 0, the function returns 1. Now, let's say you