The event loop repeatedly takes one job from the job queue, runs its callback to completion, and then processes the next job. It runs on one thread, so jobs do not execute simultaneously. Each job combines event data with the callback that handles it. section 15.15
Keep these rules in mind:
- Events such as clicks, typing, and AJAX completion add jobs unpredictably to the queue. section 15.15
- Asynchronous work cannot normally return its eventual result; pass that result to a callback instead. section 15.30
Adding shoes to a cart
A click callback starts an AJAX request and changes the button to “loading.” When the request completes, another queued job runs its callback, updates the cart, renders the icon, and restores the button text. section 15.17
Use the diagram to trace how queued events, callbacks, and the single-threaded event loop interact. section 15.15










