Episode 1 — Fundamentals / 1.17 — Additional JavaScript Topics

1.17 — Exercise Questions: Additional Topics

Practice for Section 1.17throttle / debounce and JSON.

How to use this material (instructions)

  1. Read README.md1.17.a1.17.b.
  2. Answer closed-book — then compare to lessons.
  3. Interview prep1.17-Interview-Questions.md.
  4. Cheat sheet1.17-Quick-Revision.md.

Throttle & debounce (Q1–Q12)

Q1. Define throttle in one sentence.

Q2. Define debounce in one sentence.

Q3. Live search calling an API on input — which pattern and why?

Q4. Log scroll position while user scrolls but at most every 100ms — which pattern?

Q5. Why use { passive: true } on a scroll listener that only reads scrollY?

Q6. If debounce(fn, 300) is called 10 times in 200ms, how many times does fn run?

Q7. After Q6, if the user waits 400ms with no more calls, how many times does fn run total?

Q8. Name one downside of debouncing critical instant feedback (e.g. button disabled state).

Q9. What is requestAnimationFrame useful for compared to a raw scroll handler?

Q10. Exercise: Implement debounce that returns a wrapper (skeleton OK — describe setTimeout / clearTimeout).

Q11. Resize: run heavy layout once after user stops dragging — which pattern?

Q12. Can throttle guarantee a final call after the last scroll event without extra logic?


JSON (Q13–Q24)

Q13. What does JSON.stringify({ a: 1 }) return?

Q14. What does JSON.parse('{"a":1}') return (type)?

Q15. Why must object keys in JSON be double-quoted strings?

Q16. What happens if JSON.parse receives invalid text?

Q17. Why does JSON.stringify throw on a circular object?

Q18. Does JSON.stringify preserve Date objects as Dates?

Q19. Store { x: 10 } in localStorage under key cfg — show set and get with parse.

Q20. Why use try/catch around JSON.parse of localStorage data?

Q21. JSON.stringify(undefined) — what is the result?

Q22. JSON.stringify([1, undefined, 2]) — what appears for the middle element?

Q23. True or false: JSON.parse revives functions stored in JSON.

Q24. Exercise: fetch JSON from a public API — is res.json() the same family as JSON.parse conceptually?


Answer hints

QHint
Q3Debounce — wait for typing pause
Q4Throttle
Q60 times until quiet
Q71 time after 300ms quiet
Q16SyntaxError
Q22null (undefined in array → null in JSON)

← Back to 1.17 — README