Recursion can be a tough concept to first understand but can be a useful tool in a programmer’s toolbox. In the plainest definition, a recursive function is a function that calls on itself until the function reaches its base case. The base case is the end condition where we do not need to call on the function anymore. Some examples of a base case are the last value of an array, a counter reaching zero, a string in an array of strings equals a certain word. So, like a nesting doll, the function will have a function of itself inside it and another one inside that one and on and on until we reach the base case.
That was a little confusing to understand so let’s go through an example. One of the basic examples of recursion is a factorial. A factorial of a number n, is the product of all positive numbers less than or equal to n. A factorial is denoted by n!.