A base case, which is a condition under which the function returns without making another recursive call, this is what terminates the recursion. And a recursive case, which reduces the problem to a smaller version of itself and calls the function on that smaller version. Both pieces are essential. Without a base case, the function calls itself forever and crashes the stack. Without a recursive case, it isn't recursion, just a regular function. The recursive case also has to actually move toward the base case: calling factorial(n - 1) from a negative n recurses forever because subtracting one from a negative never reaches zero.
Programming Fundamentals · Interview question
What are the two parts every recursive function needs?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Recursion
A function that calls itself. The base case, the recursive case, the call stack, and the question of when to use recursion vs a loop.