The difference between JavaScript timer setTimeout and setInterval

the difference:

  1. setTimeoutWhen the delay time is up, call this callback function. After calling it once, the timer ends.
  2. setIntervalCall 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);

Guess you like

Origin blog.csdn.net/Jack_lzx/article/details/109270229