Completed
Available
Locked · open anytime

Level 3: Advanced JavaScript Exercises

Level 3 covers the patterns you meet in every serious JavaScript codebase: closures that keep state private, functions that wrap functions, classes with #private fields, and asynchronous code with Promises and async/await. Each lesson points out the one mistake people make most often with it.

Two projects close the level: an Event Emitter like the one in Node.js and the DOM, and a Retry with Backoff helper for flaky network calls. Timers and fake APIs stand in for the network, so everything runs in your browser.

The 9 exercises in this level

  1. 1 Closures in JavaScript Private state without a class Keep a variable alive inside a function's scope and hand out only the functions allowed to touch it — the trick behind counters and private state. Start here — no prerequisites
  2. 2 Higher-Order Functions Functions that wrap functions Wrap any function in another one to change how it behaves — here, a run-once guard like the ones apps put around their setup code. Recommended first: Closures in JavaScript
  3. 3 Classes and #private Fields Getters, setters and hidden state Build a JavaScript class whose data is hidden in a #private field and read through getters and setters that look like plain properties. Start here — no prerequisites
  4. 4 extends & super Build on a parent class Make a child class that reuses its parent's constructor and methods through super, and overrides only what differs. Recommended first: Classes and #private Fields
  5. 5 Promises A value that arrives later Wrap a timer in a Promise so other code can wait for its result with then, instead of nesting callbacks. Start here — no prerequisites
  6. 6 async / await & Promise.all Many requests at once Start several API calls together and wait for all of them with Promise.all, instead of waiting for each one in turn. Recommended first: Promises
  7. 7 Generators (function*) Values made on demand Write a function* that hands out numbers one at a time with yield, so even an endless sequence costs nothing until you ask for the next value. Recommended first: Closures in JavaScript
  8. 8 Event Emitter Project — on, off and emit Build the publish/subscribe object behind Node's EventEmitter and DOM listeners: register callbacks by name, remove them, fire them with data. Recommended first: Classes and #private Fields, Higher-Order Functions
  9. 9 Retry with Backoff Project — survive flaky requests Write the helper that real apps wrap around unreliable network calls: try again after a short, growing pause, and give up with the last error. Recommended first: async / await & Promise.all

Frequently asked questions

Do I need to finish Levels 1 and 2 first?
It helps. This level assumes you can already write functions, loops, arrays and objects. All levels stay open, so you can jump in and go back when something feels unfamiliar.
How can async code be tested without a real server?
The tests pass in small fake functions that return Promises and resolve after a few milliseconds with setTimeout. They behave like slow API calls, so your code works the same way it would with fetch.
Why is awaiting inside a for loop a problem?
Each await waits for the previous request to finish before the next one starts, so ten 100 ms requests take a full second. Starting them all and awaiting Promise.all takes about 100 ms.
Are classes better than closures for private state?
Both work. Closures suit small objects made by a factory function; classes with #private fields read better when there are several methods or when you want to extend them with extends.