the-event-loop Flashcards

1
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the JavaScript Event Loop?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly