Recursion is very important to functional programming in any language. Many functional languages go so far as to require recursion for iteration by not providing for
and while
loop statements; this is only possible when tail-call elimination is guaranteed by the language, which is not the case for JavaScript. A quick primer on recursion was given in , Fundamentals of Functional Programming. But in this section, we'll dig deeper into exactly how recursion works in JavaScript.