Skip to content

Predict the output

Name every output the program can produce, and only those. This is the mode that destroys the “I know roughly what happens” illusion faster than anything else here, because naming an output that cannot happen is exactly as wrong as missing one that can.

Four lines, one order

A synchronous log, a timer, and a promise callback, in the order they were written.

1function* script(t) {2  yield t.print("script start");3 4  // setTimeout(..., 0) — a macrotask.5  yield t.macrotask("timeout", 0, log(t, "timeout"));6 7  // Promise.resolve().then(...) — a microtask.8  yield t.microtask("promise", log(t, "promise"));9 10  yield t.print("script end");11}12 13function* log(t, text) {14  yield t.print(text);15}

Name every output this program can produce. One per box, exactly as it would be printed. Naming an output it cannot produce costs the same as missing one it can.

Explained in The event loop, drawn.

Everything you do here stays in this browser.