+ 2
Why does the following code outputs 6? [JS]
function addRek( x ) { if( x == 0 ) { return 0; } else { return x + addRek( x - 1 ); } } console.log( addRek(3) ); Thank you. :).
5 Respuestas
+ 6
This program recursively calls addRek till your passed value isn't reduced to zero.
so output is
3+2+1=6
+ 5
Sorry for my explanation but does it really outputs 6
0
dude. I don't get it
0
heyo. thanks for the nice response man. But I didn't get it haha. I will probably ask a friend one on one so he could explain it to me. Thank you again ; )
0
yeah it really does outputs 6 haha