Tasks, microtasks execution order in javascript - snippet example

1 · Adrian Matei · Aug. 13, 2021, 10 p.m.
What is the order in which the following texts are logged via console.log ? console.log('1 - start'); setTimeout(() => console.log('2 - setTimeout1'), 0); Promise.resolve('Success') .then(()=> console.log('3 - promise1')) .then(()=> console.log('4 - promise2')); setTimeout(() => console.log('5 - setTimeout2'), 0); console.log('6 - end'); Output 1 - start// statement is executed directly in the script (first "Run script" task) 5 - end // part of the first "Run script" task gets executed ...