Skip to content

Instantly share code, notes, and snippets.

@remy727
Created January 28, 2022 08:28
Show Gist options
  • Save remy727/3303a0ffc8ef4f48e94d3fe3346c0d68 to your computer and use it in GitHub Desktop.
Save remy727/3303a0ffc8ef4f48e94d3fe3346c0d68 to your computer and use it in GitHub Desktop.
JavaScript Event Loop
setTimeout(() => console.log(1), 100)
setTimeout(() => console.log(2), 0)
Promise.resolve(42).then(() => {
console.log(3);
setTimeout(() => console.log(4), 50);
})
.then(() => Promise.reject(new Error(22)))
.then(() => console.log(5))
.catch((e) => console.log(6, e.message))
console.log(7)
// answers:
7
3
6 22
2
4
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment