Predict the event loop order
intermediate Event loop Challenge 12 of 18
Read the snippet in the editor’s comment and work out the order in which it logs its labels. Return that order from predictOrder() as an array. The last test runs the real snippet, so you cannot argue with the result.
Requirements
- Return an array containing each of the labels
AtoGexactly once. - The array must be in the order the snippet logs them.
- Be ready to explain each position in terms of the call stack, the microtask queue and the macrotask (timer) queue.
Expected output
predictOrder() → ['A', 'E', 'G', 'C', 'D', 'F', 'B']
Test cases (5)
- ○synchronous logs come first
- ○the timer runs last
- ○microtasks run in queue order
- ○lists every label exactly once
- ○matches the order the engine actually produces
solution.jsExecutes in your browser
Ctrl/⌘ + Enter to run tests · your code is saved in this browser
Results
Run the tests to see results here.