I already checked forum, I saw a few with a similar title but not one that answered my question. I noticed if I create a recursion function the return statement returns after the termination statement it looks like. Could someone explain how this works to me? thanks
function recur(n=10){
if(n===0){
return "";
}
console.log(n);
return "A" + recur(n-1);
}
recur()
The end result is:
10
9
8
7
6
5
4
3
2
1
"AAAAAAAAAA"
I expected it to return A for each instance of the function, because I thought every statement in the function definition would be called for every instance of the function, like this:
10
"A"
9
"A"
8
"A"
7
"A"
6
"A"
5
"A"
4
"A"
3
"A"
2
"A"
1
"A"
So to reiterate why didn't the function return A like I was expecting, what pattern of how a function operates am I misunderstanding?
