The function calls itself on a simpler version of the same problem. Here a negative exponent becomes a positive one, and the positive case does the real work.
if (exp < 0) return 1 / power(base, -exp); let result = 1; for (let i = 0; i < exp; i++) result *= base; return result;


