Understanding Recursion in JavaScript
Published on:Recursion happens when a function calls itself over and over.
A function that calls itself over and over is called a recursive function. Here's an example of a recursive function:
function helloWorld() {
console.log('Hello world')
helloWorld()
}
(Don't try this code because your browser would hang). I'll explain how you write a proper recursive function and why you may want to use one.