← Back to Roadmap

setTimeout & setInterval

Easy

In plain terms

setTimeout runs a callback after a delay. setInterval runs repeatedly. Both return an ID for clearTimeout/clearInterval. Times are approximate.

What you need to know

  • setTimeout(fn, ms)
  • setInterval, clearTimeout, clearInterval
  • Async timing

Try it yourself

Copy the code below and run it in your browser console or a code editor:

const id = setTimeout(() => console.log('Later'), 1000); clearTimeout(id); setInterval(() => console.log('tick'), 500);

Learn more

Dive deeper with these trusted resources: