Put in order · JavaScript and TypeScript course · Module 4: Asynchronous JavaScript

Execution Order: Synchronous vs Asynchronous

Arrange the execution order of this code: console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); console.log('D');

Items to put in order

  • console.log('D') - synchronous
  • console.log('C') - microtask (Promise.then)
  • console.log('B') - macrotask (setTimeout)
  • console.log('A') - synchronous

You can check the correct answer by solving this task in the CodeWorlds game.