0
Recursive Functions
Can I get explanations on how recursive Functions work with reference to countdown of numbers?
4 Réponses
+ 4
recursive functions are functions calling themselves...
so the first requirement is to have a base case to stop the recursion else you've got a stack overflow error ^^
to countdown numbers recursively, the base case is reached when the count reach zero (or is less than zero).
also, the initial count must be passed as argument to the initial call:
function countdown(count) {
if (count<0) return;
console.log(count);
countdown(count-1);
}
countdown(10);
+ 1
Just see this post 👇👇
https://www.sololearn.com/Discuss/307407/?ref=app
+ 1
Link opens same discussion. Which one is the relevant answer?