Websites, like newspaper websites, take advantage of these non-blocking properties to provide a better user experience. Generally, a site’s code is written so that users don’t have to wait for a giant image to load before being allowed to read the actual article—rather, that text is rendered first and then the image can load in the background.
To read more about the event loop, read the MDN documentation:
To get a glimpse of how the event loop works, take a look at the code in the code editor.
We’ll be using
setTimeout(), which will pass a function call to the queue. The first argument is a callback and the second argument is the number of milliseconds the program must wait before the callback can be run.
console.log() calls are run from the stack.
What if we change the
setTimeout() to be
0? Essentially the callback doesn’t need to wait before it can be called. Do you think that this change will affect the order?