In what order will the logs below show up in the console?
console.log('First') setTimeout(function () { console.log('Second') }, 0) new Promise(function (res) { res('Third') }).then(console.log) console.log('Fourth')
In what order will the logs below show up in the console?
console.log('First') setTimeout(function () { console.log('Second') }, 0) new Promise(function (res) { res('Third') }).then(console.log) console.log('Fourth')
The answer is First, Fourth, Third, Second.
To fully understand this one you need an understanding of JavaScript’s event loop. Specifically, the Call Stack, Task Queue, Web APIs (for setTimeout), and the Job Queue. You could watch this video, which is perhaps the most famous JS conference talk ever given. Or you could just, not do that and enjoy your Monday instead - no judgement here.