Skip to content

Day 3: Timers (setTimeout & setInterval)

Schedule deferred and recurring code execution with browser timers.

// setTimeout: runs once after delay
const timeoutId = setTimeout(() => {
console.log('Executed after 2 seconds');
}, 2000);
// setInterval: runs continuously every interval
let count = 5;
const intervalId = setInterval(() => {
console.log(count);
count--;
if (count === 0) clearInterval(intervalId); // stops timer
}, 1000);
  1. Build a functional stopwatch with Start, Stop, and Reset buttons.