0

Recursive Functions

Can I get explanations on how recursive Functions work with reference to countdown of numbers?

15th May 2021, 1:53 PM
Kwaku Tutu
Kwaku Tutu - avatar
4 Antworten
+ 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);
16th May 2021, 4:07 PM
visph
visph - avatar
15th May 2021, 1:57 PM
Sâñtôsh
Sâñtôsh - avatar
+ 1
Link opens same discussion. Which one is the relevant answer?
15th May 2021, 2:02 PM
Kwaku Tutu
Kwaku Tutu - avatar
15th May 2021, 2:29 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar