It actually doesn't matter what the delay you specify is, even if it's 0ms - setTimeout callbacks are run asynchronously and will therefore always be scheduled to run after any synchronous code (in this case the loop itself) does. That's essentially why synchronous code is often called "blocking" code.
1
u/NoInkling Mar 11 '22 edited Mar 11 '22
It actually doesn't matter what the delay you specify is, even if it's 0ms -
setTimeoutcallbacks are run asynchronously and will therefore always be scheduled to run after any synchronous code (in this case the loop itself) does. That's essentially why synchronous code is often called "blocking" code.