Explorer
Node.js

Write a function `eventLoopOrder()` that returns the order of execution: sync code runs first, then microtasks (Promise), then macrotasks (setTimeout).

Problem Statement

Write a function `eventLoopOrder()` that returns the order of execution: sync code runs first, then microtasks (Promise), then macrotasks (setTimeout).

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: The event loop processes: 1) Sync code, 2) Microtasks (Promise.then), 3) Macrotasks (setTimeout). šŸ’” Hint 2: process.nextTick runs before promise microtasks in Node.js. šŸ’” Hint 3: Push strings in the correct order to demonstrate understanding. āœ… Solution: ```javascript function eventLoopOrder() { return ["sync", "promise (microtask)", "setTimeout (macrotask)"]; } ```

Event Loop Order

Medium
Write a function `eventLoopOrder()` that returns the order of execution: sync code runs first, then microtasks (Promise), then macrotasks (setTimeout).
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
["sync","promise (microtask)","setTimeout (macrotask)"]