I understand the logic of recursion a function calls a function with base case then terminate, what I have here is a code which logs a simple recursion, what I don't get is it started logging with the condition reached, condition met: 0?
function factorialize(num) {
if(num === 0){
console.log('condition met: '+num);
return 1;
}
var x = factorialize(num-1); // iterate
var toReturn = num*x;
console.log("Current call: num = " + num
+ " x = " + x
+ "\n"
+ "Returning " + toReturn
);
return toReturn;
}
factorialize(5);
I was expecting this code to log the output first and lastly the condition is reached?
output and demo