18. What is Event Loop?

The mechanism built into JavaScript that manages the asynchronous execution of code.

  • First, synchronous code is executed.
  • If asynchronous functions are called, they are added to the queue. They are executed one after the other when the synchronous code they were called from finishes computation.

A good example illustrating the Event Loop in action is the setTimeout function. It schedules a task to be added to the queue after a specified time. Therefore, there's no guarantee of executing the function at the exact time provided as an argument, but it is guaranteed not to be executed earlier. If synchronous code takes longer than the time set for the function to run, the asynchronous code must wait.

For more information, you can check here.

devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.