Sikau

JavaScript · Day 50 · about 25 min

Timers

Countdowns with setTimeout and setInterval.

Not right now — later

So far, every line ran immediately. But apps often need to wait: a reminder in 5 minutes, a clock ticking every second, a message that fades after 3 seconds. JavaScript has timers for this.

setTimeout: once, later

console.log("Putting the kettle on");

setTimeout(() => {
  console.log("Chiya is ready! ☕");
}, 1000);

console.log("Reading the news meanwhile");

The rest of this lesson

  • setInterval: again and againexplain
  • Timers don't pause your codeexplain
  • Predict the orderpredict
  • Order with a 0 ms timerpredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript