For example console.log isn’t slow, but doing a while loop from one to ten billion is slow, doing image processing is slow, and network request is slow.
what happens when things are slow?
The browser gets stucked. While the request is handled, the browser can’t render thereby users can’t do anything until those requests complete.
console.log('hello')
// this part goes to WebAPIs
setTimeout(function() { console.log('there')}, 3000)
console.log('how are you?')
// hello
// how are you?
// thereBut how is this possible if JavaScript runtime is single threaded? Because browser is more than just the Runtime. It provides us with WebAPIs, which we can make calls to. So it’s working as multi threads in the back. This diagram is basically identical for node, except the fact that it’s using C++ APIs instead of WebAPIs.

Event loop looks at the stack and the task queue. If the stack is empty, it takes the first thing on the queue and pushes it on to the stack.
setTimeout is not guaranteed time to execution, it’s a minimum time to execution.
console.log('hello1')
// setTimeout zero doesn't run immediately
setTimeout(function() {
console.log('hello2')
}, 0)
console.log('hello3')
// hello1
// hello3
// hello2Conclusion : Don’t put slow code on the stack because when you do that, the browser can’t do what it needs to do, creating a nice fluid UI.
Reference
https://www.youtube.com/watch?v=8aGhZQkoFbQ&t=821s