InterviewSolution
| 1. |
Explain event loop in Node.js. |
|
Answer» The event loop in JavaScript enables asynchronous programming. With JS, every OPERATION takes place on a single thread, but through smart data STRUCTURES, we can create the illusion of multi-threading. With the Event Loop, any async WORK is handled by a queue and listener. Consider the diagram below: Therefore, when an async function (or an I/O) needs to be executed, the main thread relays it to another thread, allowing V8 (Javascript engine) to continue processing or running its code. In the event loop, there are different phases, like pending callbacks, closing callbacks, timers, idle or preparing, polling, and checking, with different FIFO (First-In-First-Out) queues. |
|