Labs ICT
Pro Login

Event Loop

1 min read | JavaScript Tutorial

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

The Event Loop

The event loop is what allows JavaScript (single-threaded) to handle async operations. It constantly checks the call stack and task queues.

console.log("Start");

setTimeout(() => console.log("Timeout"), 0);

console.log("End");

Call Stack & Task Queue

The call stack runs synchronous code. Async callbacks (like setTimeout) go to the task queue and run only after the stack is empty.

function a() {
  b();
}
function b() {
  console.log("Inside B");
}
a();
console.log("Global end");

Microtasks vs Macrotasks

Promise callbacks are microtasks — they run before macrotasks (setTimeout, setInterval). Microtasks have higher priority.

console.log("1");

setTimeout(() => console.log("2"), 0);

Promise.resolve().then(() => console.log("3"));

console.log("4");