Quantcast
Viewing latest article 3
Browse Latest Browse All 7

Answer by Siddaram H for How is Javascript single threaded?

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


Viewing latest article 3
Browse Latest Browse All 7

Trending Articles