Frontend & browser·JavaScript in the browser
your `setTimeout(fn, 0)` did not run immediately, it ran after the browser got a chance to paint.
Task
Also calledmacrotask, task queue
One unit of work the browser picks off a queue and runs to completion: a script, a timer callback, an event handler, a network callback. Between tasks the browser is free to render, which is why breaking long work into separate tasks is what keeps a page responsive. Timers have a clamped minimum delay and background tabs throttle them heavily, so `setTimeout(fn, 0)` means 'soon', never 'now'.