Pages

Showing posts with label event loop. Show all posts
Showing posts with label event loop. Show all posts

[JS] Understand Javascript event loop

Ever wonder how a single threaded language like Javascript can support concurrency? Of course, via asynchronous callback you will say. But how exactly does it work? or why setTimeout to zero does not enforce a function to be executed immediately?


console.log('Top');

setTimeout(function() {
  console.log('Middle');
}, 0); 

console.log('Bottom');