– 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?
Note: Stack is where your steps being processed. There a task queue to handle callback as well.
– 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.
– 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
-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