Перейти к основному содержимому
← ⚡ JavaScript & the browser·Модуль C6 · Урок 11
ЗаданиеQuick 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
Теория

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.

🔒

Зарегистрируйся чтобы кодить

Теория открыта всем. Интерактивный редактор, живой превью и проверка открываются с 7-дневным бесплатным trial — нужна карта, отмена в любое время.

Регистрация — бесплатный trial →

Первые 10 уроков в каждом треке — бесплатные. Карта не нужна.

← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.