I'm a beginner in Javascript. And while trying recursion by myself, i got some strange result using while loop. And just the right result using If statement.
Here's the code and the result :
var test = function f(n){
while(n > 0){
document.write(n);
f(--n);
}
};
test(5);
And the result :
5432112113211211432112113211211
While using If statement
var test = function f(n){
if(n > 0){
document.write(n);
f(--n);
}
};
test(5);
The result is :
54321
I can't really debug it in the while case. It gets me confused at some point to be honest.