Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

Understanding JavaScript Event Loop

Learn how JavaScript handles asynchronous operations with the event loop.

jiocoder TeamUpdated Jun 6, 20261 min readJavaScript
Understanding JavaScript Event Loop

How Event Loop Works#

The event loop is what allows JavaScript to perform non-blocking operations. It continuously checks the call stack and callback queue.

Call Stack#

Code
function first() {
  console.log('First');
  second();
}

function second() {
  console.log('Second');
  third();
}

function third() {
  console.log('Third');
}

first(); // Call stack: first -> second -> third

Asynchronous Operations#

Code
console.log('Start');

setTimeout(() => {
  console.log('Timeout');
}, 0);

Promise.resolve().then(() => {
  console.log('Promise');
});

console.log('End');

// Output: Start, End, Promise, Timeout

Microtasks vs Macrotasks#

  • Microtasks: Promises, queueMicrotask
  • Macrotasks: setTimeout, setInterval, I/O
  • Microtasks execute before macrotasks

Article discussion

(0)

Join the discussion — login to comment and help other developers.

Login to comment