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