Episode 1 — Fundamentals / 1.17 — Additional JavaScript Topics
1.17 — Additional Topics: Quick Revision
Episode 1 supplement — print-friendly.
How to use
Skim → drill weak spots in 1.17.a / 1.17.b → 1.17-Exercise-Questions.md.
Throttle vs debounce
| Throttle | Debounce | |
|---|---|---|
| Idea | Max 1 call per wait ms while firing | Run after delay ms quiet` |
| Examples | Scroll spy, sampled metrics | Search-as-you-type, resize-end layout |
| Timer | Last-run timestamp (typical) | setTimeout reset each call |
Scroll performance: combine with { passive: true } when not calling preventDefault.
Visual sync: consider requestAnimationFrame.
JSON (Episode 1 scope)
JSON.stringify({ a: 1 }); // '{"a":1}'
JSON.parse('{"a":1}'); // { a: 1 }
localStorage.setItem("k", JSON.stringify(obj));
JSON.parse(localStorage.getItem("k") ?? "{}");
| API | Role |
|---|---|
JSON.stringify(value) | Value → string (throws on cycle) |
JSON.parse(text) | Valid JSON string → value (SyntaxError if bad) |
response.json() | fetch helper — parse body as JSON |
Not in JSON: functions, undefined (dropped in objects), Symbol keys, arbitrary class types (plain objects round-trip).
One-liners
- Throttle = cap frequency.
- Debounce = wait for silence.
parse/stringify= bridge objects ↔ text for HTTP and storage.
End of 1.17 quick revision.