What is the output of the following? “`js const p = new Promise(resolve => { console.log(‘A’); resolve(‘B’); console.log(‘C’); }); p.then(v => console.log(v)); console.log(‘D’); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following? “`js const p = new Promise(resolve => { console.log(‘A’); resolve(‘B’); console.log(‘C’); }); p.then(v => console.log(v)); console.log(‘D’); “`

Key points

  • The promise resolves with 'B' after logging 'A' and 'C'
  • The `then` method logs the resolved value 'B'
  • Logging 'D' happens after the promise is resolved
  • The order of operations is A, C, D, B

Ready to go further?

Related questions