Write a Recursive Function in JavaScript

InstructorAnjana Vakil

Share this video with your friends

Send Tweet

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.