Timers – setTimeout, setInterval, clearTimeout, and clearInterval
Video
JavaScript Notes
JavaScript
// How to use setTimeout, clearTimeout, setInterval
// and clearInterval
function log(msg) {
console.log('MESSAGE', msg);
clearInterval(tommy);
}
let timmy = setTimeout(log, 1000, 'Hello');
// 1000 means 1 second – returns 'MESSAGE Hello'
clearTimeout(timmy);
let tommy = setInterval(log, 500, 'Goodbye');
Feedback
Submit and view feedback