Lesson
Write a Recursive Function in JavaScript
A recursive function - a function that calls itself - is a key tool in every functional programmer's toolbox. The body of a recursive function needs two main parts: - a recursive case, in which the recursive call is made, and - a base case, which does not...
- Duration
- 3 min
- Access
- Free
- Transcript
- Needs source
A recursive function - a function that calls itself - is a key tool in every functional programmer's toolbox. The body of a recursive function needs two main parts:
- a recursive case, in which the recursive call is made, and
- a base case, which does not involve recursion and prevents the function from recursing infinitely.
In this lesson we'll learn the anatomy of a recursive function by writing a function to compute the factorial of a positive integer.