Created
February 2, 2020 10:17
-
-
Save qant/6c52821222c6f0ca0f4c7ad8ca005755 to your computer and use it in GitHub Desktop.
Event loop javascript order
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
//https://developer.mozilla.org/es/docs/Web/JavaScript/EventLoop | |
//https://www.youtube.com/watch?v=8aGhZQkoFbQ | |
console.log("1"); | |
console.log("2"); | |
console.log("3"); | |
console.log("4"); | |
console.log("5"); | |
console.log("--------------"); | |
// | |
console.log("1"); | |
setTimeout(function() { | |
console.log("setTimeout 1"); | |
}, 0); | |
console.log("2"); | |
setTimeout(function() { | |
console.log("setTimeout 2"); | |
}, 0); | |
console.log("3"); | |
setTimeout(function() { | |
console.log("setTimeout 3"); | |
}, 0); | |
console.log("--------------"); | |
console.log("1"); | |
new Promise(function(resolve) { | |
resolve("Promise 1"); | |
}).then(console.log); | |
console.log("2"); | |
new Promise(function(resolve) { | |
resolve("Promise 2"); | |
}).then(console.log); | |
console.log("3"); | |
(function() { | |
console.log("(function(){}) 3"); | |
})(); | |
/* | |
1 | |
app.js:4 2 | |
app.js:5 3 | |
app.js:6 4 | |
app.js:7 5 | |
app.js:8 -------------- | |
app.js:11 1 | |
app.js:15 2 | |
app.js:19 3 | |
app.js:24 -------------- | |
app.js:26 1 | |
app.js:31 2 | |
app.js:37 3 | |
app.js:40 (function(){}) 3 | |
Promise 1 | |
Promise 2 | |
app.js:13 setTimeout 1 | |
app.js:17 setTimeout 2 | |
app.js:21 setTimeout 3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment