+ 1
[JS] Can someone explain the output?
Given is the following function from a challenge: function mlt(a, b) { if(!(a && b)) { return 0; } else if(b == 1) { return a;} else{ return (a + mlt(a, b-1)); } } console.log(mlt(3, 11)); // returns 33 console.log(mlt(7, 1)); // returns 7 I understand the second output (7), but not the first one (33), since it is nested. I have no idea, how on earth it results 33. Would somebody be so kind and explain it?
4 Antworten
0
Yeah, in the end it's 3+3, but that equals 6 in common math.
It looks like it is treated as string "3"+"3" = "33"
0
Thank you for your explanation!
Now I get it 😊