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)"];
}
```