The JavaScript runtime executes event handlers one at a time in the event loop. If an event handler takes a long time to execute, the user interface appears to be unresponsive or frozen. This is because the JavaScript runtime must wait for the event handler to finish. The code execution is blocked while waiting. To avoid blocking the code execution, JavaScript uses a technique called asynchronous operations.
For example, getting data from a back-end server over the Internet requires a comparatively long-running code execution. It requires us to define a function as the callback ...