Base case

The condition in a recursive function that does not cause more recursion. This is how a recursive function terminates.


Examples

function getLinkedListLength(node) {
  if (!node) {
    // base case
    return 0;
  }

  return 1 + getLinkedListLength(node.next);
}
function fibonacci(n) {
  if (n < 3) {
    // base case
    return 1;
  }

  return fib(n - 1) + fib(n - 2);
}