Given this code, predict the output order and explain why: console.log('1'); setTimeout(() => console.log('2'), 0); Promise.resolve().then(() => console.log('3')); console.log('4');
TechnicalFrontend DeveloperFrontend Angular developerJavaScript DeveloperWeb DeveloperThe output order will be: 1, 4, 3, 2.
First, '1' and '4' are logged immediately because they are synchronous. The Promise resolves next, logging '3' as it is processed in the microtask queue. Finally, the setTimeout callback executes, logging '2' from the macrotask queue, which runs after all microtasks.