the difference:
setTimeout
When the delay time is up, call this callback function. After calling it once, the timer ends.setInterval
Call this callback function every this delay time, it will be called many times, and this function will be called repeatedly.
Case:
setTimeout:
// 过1秒后输出'只输出一次'
setTimeout(function() {
console.log('只输出一次');
}, 1000);
setInterval:
// 每秒输出'继续输出'
setInterval(function() {
console.log('继续输出');
}, 1000);