Escaping the JavaScript call stack with setTimeout
What happens when we call something using
setTimeout
with a delay of 0 is that the JavaScript engine notices that it’s busy (with whatever task calledsetTimeout
) and queues thesetTimeout
code for execution immediately after the current call stack closes. In other words, it calls it as soon as possible in its own call stack.