UnderStand Recursion ...Understand Recursion..Until you really UnderStand
Recursion is nothing but an Function which is Calling itself until it Complete its Work ... So how do we Keep it in Simple terms to understand ... Let me Explain it by Code , So Consider a Scernario of Function calling itself from 10 to 1
var givenNumber = 10
function CountDown(num){
if(num === 0){
return console.log('Done');
}else{
console.log(num)
}
CountDown(num-1);
}
CountDown(givenNumber);
OutPut:
10
9
8
7
6
5
4
3
2
1
"Done"
So in the Above Code We See that , We call the Function like an mirror where it reflects its own Action on itself Until it Has
Some Condition to Stop it , Well This is it Recursion is ...
Top comments (0)