There are two sequences here: 1 3 4
and 2 6 5
. The first is produced on the first tick (before any promises have resolved, and the second on the second tick (after promise resolution).
(async() => await console.log(3))();
writes 3
to the log before the await, so the 3
appears before any promises resolve, and between 1 and 4 because of the order of the statements. (Note that the await
in this line resolves to undefined
, because console.log doesn't return anything).
For the sequence 2 6 5
, all of the console logs come after a promise resolves (or, equivalently, an await statement), and they're in natural order otherwise.