Middle
console.log('1'); setTimeout(() => console.log('2'), 0); Promise.resolve().then(() => console.log('3')); console.log('4');
sobes.tech AI
Answer from AI
The output will be:
1
4
3
2
Explanation:
console.log('1')— synchronous call, outputs1.setTimeout(..., 0)— places the function in the macro task queue, executed after the current stack and microtasks.Promise.resolve().then(...)— places the function in the micro task queue, which executes immediately after the current stack but before macro tasks.console.log('4')— synchronous call, outputs4.
Execution order:
- Synchronous code:
1,4 - Microtasks:
3 - Macrotasks:
2