Hi,
I have a question in regards to the example in the lesson Use Recursion to Create a Countdown under Javascript .
How are you able to return an empty array that is not declared yet?
As far as order of operation?
Please correct me if I’m wrong, but I think the empty array is the const countArray, but again, how can return it first without declaration.
Because I thought it was stressed early on that Javascript works top down, and that order matters as far as to what comes first and the like.
Hopefully my question makes since. I’m just trying my best to understand Javascript and not just guess at things or assume, but rather actually understand and know what I’m doing.
Thanks,
Shawn Wright
function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5));