setInterval()
A JavaScript function that runs a callback repeatedly, roughly every given number of milliseconds, until clearInterval stops it.
In more detail
The delay is a minimum: if the thread is busy, runs happen later, and they never overlap because JavaScript runs one callback at a time. A forgotten interval keeps running and keeps everything its callback references in memory, a common source of leaks.
Related terms
- setTimeout — A JavaScript function that runs a callback once after at least the given number of milliseconds, unless clearTimeout cancels it first.
- memory leak — Memory that a program keeps holding although it no longer needs it, so usage grows until the program slows down or crashes.
- polling — Having the client ask repeatedly, on its own schedule, whether something has changed or finished.
- timer drift — The growing gap between when a timer was asked to fire and when it actually fires, caused by a busy thread or scheduling delays.
Taught in
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services
- useRef Mechanics: DOM References And Mutable Persistent State — React 19 & Modern Component Architecture