I have the following code of a simple recursive function in javascript :
function print(text) {
if (!text) {
throw 'No text in input !';
}
console.log('print : '+text);
}
function stack(msg, stackSize) {
stackSize++;
print('Stack Entry '+stackSize);
if (stackSize < 4) {
stack(msg, stackSize);
} else {
print(msg);
}
print('Stack exit '+stackSize);
}
stack('foobar',0);
which produce the following output :
print : Stack Entry 1
print : Stack Entry 2
print : Stack Entry 3
print : Stack Entry 4
print : foobar
print : Stack exit 4
print : Stack exit 3
print : Stack exit 2
print : Stack exit 1
After banging my head on this very trivial code, i still don't get why the stack exit value is decrementing ?