What happens if you forget the base case in a recursive function?
The function calls itself forever, growing the call stack until the engine throws RangeError: Maximum call stack size exceeded (stack overflow). Always include a base case.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Thinking Recursively in JavaScript
When a function calls itself. It requires a base case (when to stop) and a recursive case (call with a smaller input). Use for: tree traversal, factorial, fibonacci, divide-and-conquer.
The condition that stops the recursion. Without a base case, the function calls itself forever, causing a stack overflow (RangeError: Maximum call stack size exceeded). The base case is the simplest version of the problem.
1. Identify the base case (when to stop). 2. Identify the recursive case (how to reduce the problem). 3. Trust the recursion (assume the smaller call works). 4. Combine the result with the current step.
Still have questions?
Browse all our FAQs or reach out to our support team
