Lesson 3 of 3
See recursion by watching the stack.
A recursive function calls itself on a smaller input until it hits a base case.
function factorial(n) {
if (n <= 1) return 1; // base case
return n * factorial(n - 1);
}
factorial(5); // 120Every call adds a frame to the call stack — forget the base case and you'll overflow it.