Javascript Event Loop

What you will learn

Maybe you just learned how to code in javascript, but you are struggling to understand how promises work, why to use async/await or what microtasks and macrotasks are? This course is for you!

Learn by doing
Get event loop intuition
Everything you need to be confident in the event loop

Course Progress

  1. 1

    Synchronous Execution

    What is the output order of simple synchronous code?

  2. 2

    setTimeout Basics

    How does setTimeout affect execution order?

  3. 3

    Promise Basics

    How do promises affect the event loop? Let's say we make a successful call to some API in the cloud. This is typically asynchronous. In what order will this code be executed?

  4. 4

    setTimeout vs Promise

    Which comes first: microtasks or macrotasks (a.k.a. tasks)?

  5. 5

    Multiple Promises

    How are multiple .then() callbacks ordered?

  6. 6

    Nested setTimeout

    What happens with nested setTimeout calls?

  7. 7

    Promise in setTimeout

    How do promises inside setTimeout behave?

  8. 8

    setTimeout in Promise

    How does setTimeout inside a promise behave?

  9. 9

    Async/Await Basics

    How does async/await affect execution order?

  10. 10

    Multiple Awaits

    What happens with multiple awaits?

  11. 11

    Promise Chain

    How does chaining .then() affect order?

  12. 12

    Error in Promise

    How are errors in promises handled?

  13. 13

    process.nextTick

    How does process.nextTick fit in the event loop?

  14. 14

    queueMicrotask

    How does queueMicrotask compare to Promise and setTimeout?

  15. 15

    setImmediate

    How does setImmediate fit in the event loop?

  16. 16

    Multiple Microtasks

    How are multiple microtasks ordered?

  17. 17

    Non-awaited promises

    What is the order of non-awaited functions with awaited functions inside of them?

  18. 18

    Await the first but not the second promise

    What happens if you await the first async function (the promise) and not the other one?

  19. 19

    Await the first long running fetch

    What if the first awaited function has a long running fetch inside of it?

  20. 20

    Await the second, fast running fetch

    What if the first not-awaited function has a long running fetch inside of it and you await only the second?

  21. 21

    Async Error Handling chaining

    How are errors handled in when not awaited?

  22. 22

    Awaited Async Error Handling

    How are errors handled in when awaited?

  23. 23

    Send meny requests at once?

    What if you want to do many asynchronous operations at once?

  24. 24

    Race asynchronous operations

    What happens in a race between two asynchronous operations?

  25. 25

    How do you call asynchronous operations after each other?

    What if you want to call asynchronous functions in sequence?

  26. 26

    How do you call asynchronous operations after each other, with await?

    What if you want to call asynchronous functions in sequence, with await?

  27. 27

    How does a javascript generator work?

    How does an async generator work and how is the program executed?

  28. 28

    How does an async generator yield values with an await inside?

    How does an async generator yield values, what if you await inside the generator? The closure is a bonus ;)

  29. 29

    nextTick vs. setImmediate?

    Which one is run first, nextTick or setImmediate?

  30. 30

    When do you need await?

    How does await affect the output of asynchronous functions? Can you tell which console.log writes A and which writes the unfulfilled promise, i.e. [object Promise]?

  31. 31

    What about the other way around?

    Same thing again but notice the swap of the await. Can you tell which console.log writes A and which writes the unfulfilled promise, i.e. [object Promise]?

  32. 32

    Let's put your knowledge to the test

    Can you predict the output order? If you can do it right away we know you have succeeded in learning the event loop!

  33. 33

    One more tough one, can you solve it?

    Let's put your skills to the test, solve it one go!

Find Related Courses