Asynchronous JavaScript
The event loop, promises, async/await and fetch.
Every real web app waits: for a timer, a server, a file. You will learn how JavaScript waits without freezing on one thread: the call stack, the task queue and microtasks, and why setTimeout(fn, 0) is not immediate. Then you will write asynchronous callbacks in the error-first style, replace them with promises you create, chain and recover, and move on to async and await, running work in sequence or in parallel with Promise.all, allSettled, race and any. You will call real-shaped HTTP APIs with fetch, check response.ok because fetch does not reject on a 404, send JSON, build query strings, cancel with AbortController, and finish with a weather client that retries with backoff, a paginated loader, a concurrency limit and a cached fetch. Timers and requests run on a virtual clock and a mocked network, so every test is exact.
What you will learn
- The event loop
- Timers
- Callbacks
- Promises
- async and await
- Promise.all, allSettled, race and any
- fetch and HTTP
- AbortController
- Retries with backoff
Lessons
- 1
The Event Loop and Timers
See how one thread runs your code to the end before any callback, schedule and cancel timers, predict task and microtask order, and keep long work from freezing the page.
14 exercises
- 2
Callbacks
Deliver results from asynchronous work through callbacks, follow the error-first convention, call a callback exactly once, and see why nesting and handing over control led to promises.
12 exercises
- 3
Promises
Create promises and promisify callbacks, chain then and return from every step, recover with catch and clean up with finally, and end every chain so no rejection goes unhandled.
12 exercises
- 4
Promise Patterns and async/await
Write async functions with await and try/catch, run independent work in parallel with Promise.all and allSettled, set deadlines with race, take the first success with any, and choose sequential or parallel awaits on purpose.
12 exercises
- 5
fetch and HTTP
Call HTTP APIs with fetch: check response.ok because fetch does not reject on a 404, parse and send JSON, use GET, POST, PUT and DELETE, build query strings, read a CORS error, recognize XMLHttpRequest and cancel with AbortController.
12 exercises
- 6
Putting It Together
Build the async pieces real apps need: a weather client that retries with backoff, a loader that follows every page, a concurrency limit and a cached fetch that shares requests.
9 exercises
How you practice
You practice in the browser and every exercise gives you feedback right away. This course uses these formats:
- Code exercise: 25
- Fix the bug: 12
- Predict the output: 9
- Fill in the blank: 8
- Multiple choice: 6
- Type the answer: 4
- Match the pairs: 4
- Reorder lines: 3
Aligned to
- Networking and Communication
- NC-ApplicationsNetworked Applications
- Functions
- 5.5.1Use synchronous and asynchronous callbacks
- Advanced Functions
- 4.6Asynchronous callbacks
- 4.7Promises
- 4.8Promise patterns
- 4.9async and await
- 4.10Network requests with XMLHttpRequest and fetch
- JavaScript fundamentals
- 6.11Async JavaScript basics
- 6.12Network requests with fetch()
- 6.13Working with JSON
Proto Node Labs is not affiliated with or endorsed by ACM / IEEE-CS / AAAI, JS Institute and Mozilla. Exam names are trademarks of their owners.