What is javascript asychronous programming and event loop?

Here are the notes about how I learn the concepts of javascript asynchronous programming and event loop from different online resources. Please note that the last resource is REALLY good.



– brower is powered by Google V8 engine
– have call stack basically recall where we are in the program
– single thread ( it can only do one thing at a time)

– if there are too many components on the stack, then what if one thing is slow?
– we just wait one thing to be done and then another thing?….but we are doing in browser, if then the user has to keep waiting.

How to handle this?
-asynchronous callbacks
Note: Stack is where your steps being processed. There a task queue to handle callback as well.


-In javascript, almost all I/O is non-blocking, meaning that the single thread of execution asks the runtim to perform an operation, providing a callbuck function and then moves on to do something else.
– WHen the operation has been completed, a message is enqueued along with the provided callback function. At some point in the future, the meesage is dequeued and the callback fired.

Read more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop


– Most events in javascript are asynchronous
– WHen an asynchronous event occurs, it gets into the event queue.
– The browser has inner loop, called event loop, which checks the queue and processess events, executes function


(Great explanation)

-WHen there is a callback, it will be placed in to event table and then later move to event queue (after it is completed) . There is a process constantly checking if the call stack is empty, if so then it will checks if the event queue has any functions waiting to be invoked, if it does, then the first function will be invoked and moved over to the call stack. <– this is event loop


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s