Skip to content

Instantly share code, notes, and snippets.

@krfong916
Created January 8, 2019 05:54
Show Gist options
  • Save krfong916/ef92adbcba573372735fc117d110c69b to your computer and use it in GitHub Desktop.
Save krfong916/ef92adbcba573372735fc117d110c69b to your computer and use it in GitHub Desktop.
event loop example, tasks, queueing
// 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