Why 1, 4, 3, 2: the event loop in four lines
A playground is the right place to test a claim about JavaScript instead of trusting it. Here is one that surprises most people. Type these four lines and press Run: console.log(1); setTimeout(() => console.log(2), 0); Promise.resolve().then(() => console.log(3)); console.log(4);. The Console prints 1, 4, 3, 2. The timer has a delay of zero and still comes last.
The order comes from how JavaScript schedules work. The script itself runs first, top to bottom, with nothing able to interrupt it. So 1 is printed, the timer is registered, the promise callback is queued, and 4 is printed. Only when the script has finished does the engine look at the waiting work.
There are two queues. Promise callbacks go into the microtask queue, and the engine empties it completely as soon as the current script ends. So 3 comes next. Timer callbacks are tasks, and a task runs only after the microtasks are done and the browser has had its chance to do other work. A delay of 0 means "as soon as possible after that", not "now". So 2 comes last.
Now change the code to check your model. Add await null; console.log(5); at the end. Because this playground runs your code as a module, top-level await is allowed. await null waits for one turn of the microtask queue, so the output becomes 1, 4, 3, 5, 2. The 5 comes before the timer and after the promise callback that was queued before it, which is exactly what the two-queue picture predicts. If your guess was wrong, the Console shows it at once, and that is the point of trying it.
The same method works for any question about the language: how sort compares numbers (try [10, 9, 1].sort()), what 0.1 + 0.2 really gives, or whether a Map keeps insertion order. Write the smallest code that answers the question, guess the output, then run it.
This playground has limits. It blocks network requests, so fetch, WebSocket and import from a URL are blocked, and there are no npm packages. It runs plain JavaScript only, not TypeScript or JSX. The Console prints values as text, so you cannot expand an object to look inside it, and very deep objects are cut short. An endless loop can freeze the tab, and nothing you type is saved.