the-event-loop Flashcards
What is different between “blocking” and “non-blocking” with respect to how code is executed?
In a “blocking” code execution, the program will stop or “block” at a certain point and wait for a specific event or operation to complete before continuing. This means that no other code can be executed until the blocking operation is completed. This can lead to poor performance and a less responsive user interface.
On the other hand, in “non-blocking” code execution, the program does not stop and wait for an event or operation to complete. Instead, it continues to execute other code while also listening for the completion of the event or operation. This allows for multiple events and operations to be processed at the same time, leading to better performance and a more responsive user interface.
What is the JavaScript Event Loop?
The JavaScript event loop is a mechanism that allows the execution of code in a non-blocking, asynchronous way. It constantly checks the message queue for new messages (also called “tasks”) and processes them one by one. This allows the main thread to continue executing code while also processing any asynchronous events, such as user input or network requests.