SetTimeout and scheduling function calls

Given the following code, when will the go function be executed?

 setTimeout(go, 0); 

Will it be added to the end of the job queue immediately or added to the end of the job queue after the minimum interval for setTimeout ?

+4
source share
2 answers

In most browsers, the minimum delay time is 4 ms. You can use lower values ​​without errors, but when the script actually executes, the browser will overwrite the timeout value.

https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout?redirectlocale=en-US&redirectslug=DOM%2Fwindow.setTimeout#Minimum.2F_maximum_delay_and_timeout_nesting

https://html.spec.whatwg.org/multipage/webappapis.html#timers

+2
source

with a timeout of 0, it will be immediately added to the end of the job queue

0
source

All Articles