Created
January 8, 2019 05:54
-
-
Save krfong916/ef92adbcba573372735fc117d110c69b to your computer and use it in GitHub Desktop.
event loop example, tasks, queueing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// what is the order of the statements logged to the console? | |
console.log('script start'); | |
setTimeout(function() { | |
console.log('setTimeout'); | |
}, 0); | |
Promise.resolve().then(function() { | |
console.log('promise1'); | |
}).then(function() { | |
console.log('promise2'); | |
}); | |
Promise.resolve().then(function() { | |
console.log('promise3'); | |
}).then(function() { | |
console.log('promise4'); | |
}); | |
console.log('script end') | |
console.log('script end') | |
console.log('script end') | |
/* | |
* Answer below | |
* | |
* | |
* | |
* | |
* | |
* | |
* | |
* | |
* | |
* | |
script start | |
script end | |
promise1 | |
promise2 | |
promise3 | |
promise4 | |
setTimeout | |
* | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment