The event loop, until you can predict it

The JavaScript part of the course: 20 questions, from the event loop and microtasks to closures, this, prototypes, promises, generators and memory leaks. Every one has code you can run on the page and the follow-ups interviewers ask next, and the event loop simulator steps through code one task at a time.

See the whole course

₹449 once for the whole course. Bought it already? Open your course

A question from the course, and two of its follow-ups

Core JavaScript & RuntimeHard

playground.js
console.log('1'); setTimeout(() => console.log('2'), 0); Promise.resolve().then(() => console.log('3')); queueMicrotask(() => console.log('4')); (async () => {  console.log('5');  await null;  // suspends here; the rest becomes a microtask  console.log('6');})(); console.log('7');

The question

What is the exact output of this code?

Pick one. The interviewer has two more after it.

What's in it

The first questions, as the course lists them; the rest are in the course. Each has a model answer, written the way you would give it in the room, and the follow-ups that come after it.

Core JavaScript & Runtime20 questions

  1. How does the event loop actually run your code, and why isn't setTimeout(fn, 0) immediate?

    MediumCode runs on the page3 follow-ups

  2. What is the exact output of this code? Explain the microtask queue.

    HardCode runs on the page3 follow-ups

  3. What does this refer to? Walk through the binding rules.

    MediumCode runs on the page3 follow-ups

  4. Explain call, apply and bind — then implement your own bind.

    MediumCode runs on the page3 follow-ups

  5. Explain closures — and why this loop logs 3, 3, 3.

    MediumCode runs on the page3 follow-ups

15 more questions in Core JavaScript & Runtime, each with a model answer and its follow-ups, in the course.

Step through it

The course's event loop simulator runs code one task at a time and shows the call stack, both queues and the console as it goes. Here is the first of its 3 scenarios.

Event loop simulatorPromise vs setTimeout
console.log("A"); setTimeout(() => {  console.log("setTimeout");}, 0); Promise.resolve().then(() => {  console.log("microtask");}); console.log("B");

Script start

Global code enters the call stack

Call stackLIFO

(script)

MicrotasksHigh priority

Empty

MacrotasksLow priority

Empty

Console

Nothing yet

Step 1 of 11

All of it, for one payment

This page is one part of the course. ₹449 once opens all of it: every module, the labs, all 20 company guides and the 94 machine coding problems.

See what's free and what's in the course

The course

₹449once

Lifetime access. It never renews.

GreatFrontEnd lifetime, India price: ₹7,200

199 questions across 12 modules

Checkout opens in a new tab.

The course has

  • 199 interview questions in 12 modules, each with a model answer and its follow-ups
  • 5 system design labs, an event loop simulator, an interview simulation, XSS and accessibility labs, 8 CSS battles and 10 bugs to fix
  • All 20 company guides, with every model answer
  • All 94 machine coding problems, with tests and solutions
  • Mock interviews on every guide, and up to 300 AI replies a day
  • A 15-day and a 30-day study plan
  • Every module and lab added later

Questions, answered

Something else on your mind? Write to support@codingactivist.com.

The rest of the course

Ready for the
follow-up?

Try a free problem
blur