This is because the console.log(‘D’); statement is still left in the stack after main() is popped out. So after executing console.log(‘D’); only then the stack becomes empty. Then the console.log(‘B’); is pushed into the stack from the message Queue. Note that for console.log(‘B’) to taken from the message Queue, the stack has to be empty.

--

JavaScript Dev with an affinity to React. https://anooprav7.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store