What is the accuracy of timing such as setTimeout and setInterval? What is the minimum timing millisecond?

what is the accuracy of setTimeout and setInterval timing? What is the minimum timing millisecond? Is there anything you need to pay attention to?

Mar.04,2021

setTimeout and setInterval have no precision to speak of, they just throw the task into the event loop of js, and it may be their turn to execute.

setTimeout (() = > {xxx}, 0); will only be executed for you as soon as possible, but cannot be guaranteed to be executed immediately

.

refer to
" event loop "
actual delay ratio Reason for setting the value longer

if you only talk about the precision of parameters, millisecond
refer to API document

.

computer monitors are generally refreshed at 60Hz, redrawn 60 times per second.
therefore, if you want to achieve the smoothest animation, the best interval is 1000ms 16.6ms 60, which is about equal to the animation.

Menu