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.