- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Recursion
JavaScript Functions
JavaScript Recursion
JavaScript recursion is when a function calls itself to solve a smaller version of the same problem.
Every recursive function needs a stopping point, called the base case.
Without one, the function keeps calling itself until the browser gives up.
Example
Example
javascript
function countdown(n) {
if (n === 0) {
return "Done";
}
console.log(n);
return countdown(n - 1);
}
console.log(countdown(3));