🟢 EasyCore JS📖 Theory Question

Explain the event loop, call stack, and microtask queue.

💡

Hint

Synchronous → Microtasks (all) → Next Macrotask

Full Answer

JS is single-threaded. The call stack runs sync code. Async callbacks go into task queues. The event loop picks tasks when the stack is empty.

Microtasks (Promises, queueMicrotask) drain completely after each task before the next macrotask runs.

console.log('1');
setTimeout(() => console.log('2'), 0); // macrotask
Promise.resolve().then(() => console.log('3')); // microtask
console.log('4');
// Output: 1 → 4 → 3 → 2
💡 Order: Sync → All Microtasks → Next Macrotask → All Microtasks → ...

More Core JS Questions

🟢 EasyWhat is the difference between var, let, and const?→🟢 EasyExplain closures with a practical example.→🟢 EasyWhat is hoisting in JavaScript?→🟢 EasyWhat is the difference between == and ===?→

Practice this in a timed sprint →

5 free questions, no signup required

âš¡ Start Sprint