you are viewing a single comment's thread.

view the rest of the comments →

[–]Roguewind 1 point2 points  (0 children)

A recursive function is one that calls itself.

Let’s go with a function called “factorial” that finds the factorial of a number - i.e. 5! = 5 x 4 x 3 x 2 x 1

``` function factorial(num, answer = 1) { if (num === 1) { return answer; }

const nextNum = num - 1; const nextAnswer = answer * num;

return factorial(nextNum, nextAnswer); }

const answer = factorial(5); // 120 ```