The following code has a new callstack when the debugger fires in d (jsfiddle here)
function c() {
setTimeout( d, 1000 );
}
function d() {
debugger;
}
c();
If we modify the code to use setTimeout( d(), 1000 ); which has brackets (parenthesis:)
function c() {
setTimeout( d(), 1000 );
}
function d() {
debugger;
}
c();
then the callstack has both c() and d() (jsfiddle here). Why?
You are not passing
setTimeoutthe functiondin the second example; you are instead passingd(), which is the result of callingd.The result of calling
disundefinedsince it returns nothing, which converts to the string"undefined", which is thenevaled, doing… precisely nothing.With regard to callstacks, since you are calling
dinside ofc, that is why you seecin the callstack. To clarify, your second example is the same as