Javascript uses something called Eventloop for Asynchronous calls.The setTimeout is pushed to EventLoop since it is a callback. and the main thread continues to execute. Once the main completes, Then the EventLoop pushes the data to the main stack. Ex:
console.log("1");setTimeout(function(){console.log("2");},0);console.log("3");setTimeout(function(){console.log("4");},1000);
When the timeout is 0, then the output of the code will be,
1 3 2 4
Since it first executes the calls of the Main and then brings back data from EventloopConcurrency model and Event Loop