Skip to main content
← ⚑ JavaScript & the browserΒ·Module C6 Β· Lesson 11
TaskQuick recap. Inside <script type='module'>: write function* range(n) yielding 1..n. Sum them with reduce inside a try block: const total = [...range(4)].reduce((a,b) => a+b, 0). console.log(total) β€” should print 10. Also catch any error (none expected) and log 'no error'.

Recap: Iterators, fetch, errors (C4-C6)

50 XP5 min
Theory

Quick recap β€” Modules C4-C6

Async patterns and iteration. The 4 pieces that show up in every real codebase:

  1. `for...of` β€” iterate any iterable: arrays, Maps, Sets, generators, NodeLists.
  2. **function* generator** β€” yield values lazily. for-of consumes them.
  3. `try/catch` around `await` β€” the rejection path. Without it, unhandled rejections bring down Node and noise up the browser.
  4. `Array.prototype.reduce` β€” sum, group, build any aggregate in one pass.

If any feels random, redo C5-03 / C6-04 / C4-07 / C5-09 then come back.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 15 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.