1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Write a Recursive Function in JavaScript

    javascriptJavaScript

    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.