I was browsing the html5boilerplate github and I went to see some of the interview questions and I came across this one and I don't understand why it outputs in the order it does. I assumed it would be one four two three not the output it does. Can someone explain why? sorry if it's too simplistic.
Question: What does the following code print?
console.log('one');
setTimeout(function() {
console.log('two');
}, 0);
Promise.resolve().then(function() {
console.log('three');
})
console.log('four');
The output was in this order "one" "four" "three" and finally "two"
Code Snippet
console.log('one');
setTimeout(function() {
console.log('two');
}, 0);
Promise.resolve().then(function() {
console.log('three');
})
console.log('four');
setTimeout
tasks.