Does calling setTimeout clear the callstack?

Async invocations, such as those from setTimeout, do indeed generate a new callstack.

It's not entirely clear what you're describing when you say "When i look in the callstack of both chrome and IE it seems that the setTimeout calls are waiting for the function call to return." But, one thing you can do is put a breakpoint inside of a function called by setTimeout, and see that the callstack is empty.


I can confirm that the stack is cleared.

Consider this scenario:

function a() {
     b();   
}

function b() {
     c();   
}

function c() {
    debugger;
    setTimeout( d, 1000 );
}

function d() {
    debugger;
}

a();

So there are two breakpoints - one at the beginning of function c, and one at the beginning of function d.

Stack at first breakpoint:

  • c()
  • b()
  • a()

Stack at second breakpoint:

  • d()

Live demo: http://jsfiddle.net/nbf4n/1/