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