Lesson 12 of 30
The single habit that unblocks recursion for most people: trust that the smaller call already works, instead of tracing every call by hand.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
This topic is about judgment and practical tradeoffs more than a single right answer — a mock interview is the better way to test yourself on it.
Be interviewed on this →Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Here's the trap almost everyone falls into with recursion: trying to mentally trace every single call, all the way down and back up, before trusting any of it. That's exhausting, and it falls apart fast once the problem gets even a little bigger. It's also not how anyone experienced actually reads recursive code.
The way out is what's often called the leap of faith. Instead of tracing every call, you trust one thing: the smaller version of this problem already works correctly. You don't need to know how — you just need to believe the result is right, the same way you already trust that Array.prototype.map works correctly without re-reading its source code every time you use it.
Picture standing between two mirrors facing each other. You see your reflection, and inside that reflection, another reflection, and another, shrinking into the distance. You don't need to count every single reflection to know the pattern holds — you trust it continues the same way, all the way down. That trust is the leap of faith.
With recursion, the move is: assume the recursive call already returns the right answer for the smaller input, then just figure out what to do with that answer at your current step.
function sumArray(nums) {
// Base case: an empty array sums to 0. No leap needed here — it's just true.
if (nums.length === 0) {
return 0;
}
const first = nums[0];
const rest = nums.slice(1);
// THE LEAP OF FAITH: trust that sumArray(rest) already correctly
// sums everything except `first` — without tracing how.
// Your only job at this step is deciding what to do with that trusted answer.
return first + sumArray(rest);
}
console.log(sumArray([2, 4, 6])); // 12
To trust this, only check two things: does sumArray([]) clearly return the right answer (yes, 0)? And if sumArray(rest) is correct, does first + sumArray(rest) correctly sum the whole array (yes)? That's the whole proof. No call-by-call tracing required.
sumArray([]) returned the wrong thing, the whole leap would be built on nothing. Always check the base case first, by itself, before trusting anything built on top of it.This builds directly on the last lesson's countdown example — same self-calling pattern, same base case idea. What's new here isn't a new mechanism, it's a new way of reading one: trusting the smaller call instead of tracing it, which is the mental shift that makes every recursive problem afterward easier to approach.