Skip to content
FrontDepth, Home

Back to the topic

Practice: Event Loop

Answer first, then compare. Rate yourself honestly — it drives your weak-areas list.

4 predict-output · 4 open

Questions up to level

Shows questions up to the selected level.

No practice questions for this level yet.

  1. Predict the outputJunior

    In what order are the lines logged?

    JavaScript
    console.log("start");
    
    setTimeout(() => {
      console.log("timeout 1");
      setTimeout(() => console.log("timeout 3"), 0);
    }, 0);
    
    setTimeout(() => console.log("timeout 2"), 0);
    
    console.log("end");
  2. Open questionJunior

    What is the event loop, and why does JavaScript need it?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  3. Predict the outputMiddle

    What does this code log, and in what order?

    JavaScript
    console.log("script start");
    
    setTimeout(() => console.log("timeout"), 0);
    
    Promise.resolve()
      .then(() => console.log("then 1"))
      .then(() => console.log("then 2"));
    
    queueMicrotask(() => console.log("microtask"));
    
    console.log("script end");
  4. Predict the outputMiddle

    What does this code log?

    JavaScript
    async function load() {
      console.log("load start");
      await null;
      console.log("load end");
    }
    
    console.log("A");
    setTimeout(() => console.log("B"), 0);
    load();
    Promise.resolve().then(() => console.log("C"));
    console.log("D");
  5. Open questionMiddle

    What is the difference between microtasks and tasks (macrotasks)?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  6. Open questionMiddle

    Why should you use requestAnimationFrame instead of setTimeout for animations?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  7. Predict the outputSenior

    What does this code log?

    JavaScript
    const log = (s) => console.log(s);
    
    setTimeout(() => log("timeout"), 0);
    
    queueMicrotask(() => {
      log("m1");
      queueMicrotask(() => log("m3"));
    });
    
    Promise.resolve()
      .then(() => log("p1"))
      .then(() => log("p2"));
    
    (async () => {
      log("async start");
      await null;
      log("async end");
      setTimeout(() => log("timeout 2"), 0);
    })();
    
    log("sync");
  8. Open questionSenior

    How do you keep the UI responsive while processing a large amount of data on the main thread?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.