The event loop is the thing that allows Node.js to operate the non-blocking input/output operations. Despite the originality, JavaScript is a single-threaded that is used for offloading the operations to the kernel of the system, when possible.

Event Loop
It allows Node JS to perform non-blocking I/O operations despite the fact. In Node.js codes runs on a single thread.

Phases of the Event loop

  • Timers
  • Pending Callbacks
  • Idle, Prepare
  • Poll
  • Check
  • Close Callbacks
Phases of Event Loop
BY Best Interview Question ON 21 Feb 2021

Example

console.log("This is first title");
setTimeout(function(){
    console.log("This is second title");
}, 1000);
console.log("This is third title");

OUTPUT

This is first title

This is third title

This is second title

 

Suggest An Answer