Call Stack
- A data structure which is a part of the JS Engine (e.g. Chrome V8)
- Keeps track of the code which is currently being interpreted along with its origin
External APIs
The JS Engine is single threaded meaning that it has one call stack and heap space (for object allocation). All code get executed synchronously in order. Since this is not always a good thing, the browser packages other capabilities apart from the JS Engine.
External APIs lets the JS Engine offload async tasks to the Browser runtime(using WebAPIs)/Node runtime(using C++ APIs) to achieve pseudo concurrency. When calling an External API a callback is to be provided. Once the execution of the External API is complete the callback code is loaded onto the callback queue.
Callback Queue
- This is where all of the callbacks line up for execution
- Since JS Engine is single threaded, the external APIs have to wait for the callbacks to get processed sequentially
Event Loop
The component which monitors the call stack and loads the stack with tasks from the callback queue