Reference documentation

setInterval

1. "Frame loss" (setInterval() adds the timer code to the queue only if there are no other code instances of the timer.) 2. Code execution interval <= expectedCopy the code

  • At 1.7s, Func1 is executing, Func2 is queuing, and Func2 is the code instance of the timer. According to the JS engine, Func3 will not join the event queue, let alone execute, which results in “frame loss”
  • At 2s, func1 finishes executing, the thread is free, and func2 starts executing, which makes func1 and func2 have no time between them, producing a result against the expected 500ms

setTimeout

  • Ensure that there are no missing time intervals (e.g., 2s to 2.5s; 3.5 s ~ 4 s)