Puzzle 1: sync, microtasks, then tasks
then B is queued only when then A runs, so it lands after queueMicrotask, which was already waiting. The timer waits for every microtask.
Async interview questions test one model: synchronous code runs to the end, then every microtask (promise callbacks, await continuations, queueMicrotask) runs, then one task (a timer, an event) runs, and the cycle repeats; with that model you can predict any output order and write Promise.all and debounce from scratch.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Predict the output: setTimeout(() => console.log(1)); Promise.resolve().then(() => { console.log(2); setTimeout(() => console.log(3)); }); console.log(4);
Write promiseRace(items) that settles like the first item to settle.
Write throttle(fn, ms) that runs fn at most once every ms milliseconds (leading call only).
Write sleep(ms) and use it in an async function that prints a, waits 100 ms, then prints b.
Explain it without notes
Explain the event loop, tasks and microtasks in your own words.
In what order do setTimeout, Promise.then, queueMicrotask and synchronous logs run, and why?
Implement Promise.all and list the edge cases you handled.
What is the difference between debounce and throttle? When would you use each?
Preview
Console
Nothing logged yet.Expected console output
sync start
sync end
then A
queueMicrotask
then B
timeout