While looking at this code:
<script>
console.log(1);
new Promise(r=>r()).then(() => console.log(2));
</script><script>
console.log(3);
</script>
it seems like 2 should be printed after 3, because it should have been queued as a microtask, just like it behaves here:
<script>
console.log(1);
new Promise(r=>r()).then(() => console.log(2));
console.log(3);
</script>
I can't find a good explanation - why would the JS engine bother to empty the microtask queue before continuing to process the next script element?