Can a stack overflow be avoided in javascript by using the setTimeout method to call a function instead of calling it directly? My understanding of setTimeout is that it sho
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:
Stack at second breakpoint:
Live demo: http://jsfiddle.net/nbf4n/1/