Recursion

A function that calls itself, typically with a guard condition that prevents infinite execution.

Below is an example of a recursive function in javascript (a common factorial example):

1
2
3
4
5
6
7
8
9

const factorial = (n) => {
  if (n == 1) {
    return 1;
  }
  return n * factorial(n - 1);
};

factorial(4); // == 24

Further Reading