Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Power

A Closer Look at Functionseasy

Course · Section 10: A Closer Look at Functions · Lecture 137: First-Class and Higher-Order Functions

Implement `pow(base, exp)` returning `base` raised to the non-negative integer `exp`, using recursion.

Sample tests

Input: pow(2, 5)
Output: 32
Input: pow(3, 0)
Output: 1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • No base case leads to a stack overflow.

Learning resources

  • MDN: Recursion
Approach & explanation (try first)

Repeated multiplication unwinds from exp down to 0, where the product is 1.

Loading...
⌘/Ctrl + Enter

Run your code to see results.