DEV Community

loading...

Discussion on: JS interview in 2 minutes / Promise

Collapse
kozlovzxc profile image
Nikita Kozlov Author

Hey 👋 Great question!

For example, if you use setTimeout, your function will be put into the execution queue, but not executed right away.

setTimeout(() => console.log(3), 0)
console.log(1)
console.log(2)
Enter fullscreen mode Exit fullscreen mode

will produce output

1
2
3
Enter fullscreen mode Exit fullscreen mode

even though console.log(3) appears before console.log(1) and console.log(2).

MDN/Even toop