What does the following code output? console.log(‘a’); setTimeout(() => console.log(‘b’), 0); Promise.resolve().then(() => console.log(‘c’)); console.log(‘d’);

JavaScript Developer Medium

JavaScript Developer — Medium

What does the following code output? console.log(‘a’); setTimeout(() => console.log(‘b’), 0); Promise.resolve().then(() => console.log(‘c’)); console.log(‘d’);

Key points

  • The order of execution is determined by the event loop in JavaScript
  • setTimeout() with 0ms delay doesn't guarantee immediate execution
  • Promises are asynchronous and executed after the current call stack is empty

Ready to go further?

Related questions