A factorial is a series of integers multiplied together. You might remember *1 * 2 * 3 * 4 * 5 * … * (n-1) * n*. That’s a factorial. Traditionally, a factorial can be presented in just about any programming language easily with a tiny bit of recursion. The real problem though is the percision at which factorials can be stored. For instance, just *15!* (that is 15 factorial) yields a gigantic *1,307,674,368,000*. Java Script can certainly store large numbers but even then there is a major limit. Imagine *100!*.

In Java Script, you can easily make a factorial function.

function factorial(n) { if ( n <= 1 ) return 1; return n * factorial(n-1); }

Let’s break down the function. The first line establishes the odd case of zero-factorial, the case where it turns out to be one. Secondly, it accounts for one-factorial which is also one. The second line contains the recursion that everyone is so fond of. You take some value of “n” and multiply it against the value of the value recursed from subsequent factorials.

There’s not really an easier and more meaningful example of recursion than the factorial.

Happy factorialing.