# Timers and the Event Loop

JavaScript does one thing at a time, so how does a page keep working while it waits? See what 'blocking' looks like, schedule work with setTimeout and setInterval, and watch the event loop decide what runs next.

Updated: November 15, 2026

## [Waiting in JavaScript](https://www.ask-codey.com/courses/javascript-in-depth/topics/javascript-async-basics)

1. [Why Code Can't Stop and Wait](https://www.ask-codey.com/lessons/javascript-async-basics-why-code-waits) (Apprentice): JavaScript runs one line at a time on one thread, so code that stands and waits freezes the whole page; asynchronous code starts a wait, carries on, and finishes the job later.
2. [Timers: setTimeout and setInterval](https://www.ask-codey.com/lessons/javascript-async-basics-timers) (Apprentice): setTimeout runs a function once after a delay, setInterval runs it again and again, and clearTimeout and clearInterval cancel them with the ID each timer hands back.
3. [The Event Loop, in Pictures](https://www.ask-codey.com/lessons/javascript-async-basics-the-event-loop) (Journeyman): The call stack runs one function at a time, finished timers wait their turn in the task queue, and the event loop moves the next one onto the stack only when the stack is empty, which is why setTimeout(fn, 0) runs after the code around it.

## [Exercise: Workout Interval Timer](https://www.ask-codey.com/courses/javascript-in-depth/topics/exercise-javascript-workout-interval-timer)

1. [Exercise: Workout Interval Timer](https://www.ask-codey.com/lessons/exercise-javascript-workout-interval-timer) (Journeyman): Build the engine of a workout interval timer, a plan of work and rest, a clock display and a countdown that runs on setInterval, and let tests with a pretend clock check it in a split second.

Source: https://www.ask-codey.com/courses/javascript-in-depth/chapters/timers-and-the-event-loop-in-javascript
