I heard recursive function is powerful so instead going through loop i tried to create a function which increments a number until it reach certain points. when it reaches i tried to return the value, but it give undefined.
CODE
var i=1;
function rec(){
i++;
console.log(i);
if(i > 100){
return i;
}else{
rec();
}
}
console.log(rec());
Here the i is incrementing until 100. but it returns undefined after the limit. Why is this happening? Also please let me know, it this kind of recursion is good then for loop?
else { return rec(); }?