I'm fairly new to programming and I'm learning about basic recursion for the first time. A result I just got playing around with a practice question in JavaScript is really baking my noodle.
function countDownRecursive(n) {
if (n == 0) {
console.log('Hooray!')
return
} else {
console.log(n)
countDownRecursive(n-1)
console.log(n)
}
}
The output of ie, countDownRecursive(3) is
3 2 1 Hooray! 1 2 3
My question is why does putting console.log() after countDownRecursive(n-1) like this cause JS to log the values in reverse?