Schedule UI updates without blocking the page.
- setTimeout
- setInterval
- requestAnimationFrame
- cleanup
setTimeout schedules a later callback; setInterval repeats until cleared. requestAnimationFrame schedules visual work before a repaint. Store timer IDs and clean them up when a component is removed. Long synchronous loops still block interaction while they run.
A timer can keep updating an element that no longer exists, and intervals can accumulate after repeated setup.
Build a countdown with start and stop controls, then prevent duplicate timers.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- Explain the core idea in your own words without reading the code.
- Change one input and predict the output before running it.
- Test one boundary or failure case, then record what you changed.