I was reading javascript documentation on 'functions' and came across this code that I am not following how it's working step by step, specifically the inner recursive function.
function factorial(n){
if ((n == 0) || (n == 1))
return 1;
else
return (n * factorial(n - 1));
}
var a, b, c, d, e;
a = factorial(1); // a gets the value 1
b = factorial(2); // b gets the value 2
c = factorial(3); // c gets the value 6
d = factorial(4); // d gets the value 24
e = factorial(5); // e gets the value 120
I am not following the logic beyond the first if statement. Could someone spell it out. I have already ran the code and works just as specified.