JavaScriptQuestion 17 of 36
Differences between setTimeout() and setInterval()?
Answer out loud or in your head first, then compare.
Answer
setTimeout:
JavaScript
setTimeout(() => {
console.log("Hello");
}, 1000);runs the callback once.
setInterval:
JavaScript
const id = setInterval(() => {
console.log("Hello");
}, 1000);runs it repeatedly.
Stopping it:
JavaScript
clearInterval(id);Pitfall: 1000 ms is a minimum delay, not a guarantee of the exact moment it runs.
How did it go? Be honest — “Not yet” puts the question on your review list.