Aishwar Aishwar - 6 months ago 11
Javascript Question

Is setTimeout with no delay the same as executing the function instantly?

I am looking at some existing code in a web application. I saw this:

window.setTimeout(function () { ... })


Is this the same as just executing the function content right away?

Answer

There is a minimum delay that setTimeout uses (4ms as per HTML5, Firefox 3.6 uses 10ms). There is a discussion about it on the Mozilla Developer Center documentation page. Everything I can find specifies that the delay parameter is required, but I don't get an error (or even a strict warning) without it (in firefox). My best guess is that the minimum is used in that case.