I would like to put
var minValue = 0; if ( typeof callback == 'function' ) { setTimeout( callback, minValue ); }
this code when I implement callback function with JavaScript.
But I've found that modern browsers and some old browsers
have different minimum timeout value.
I know that Zero cannot be minimum value.
What would be minimum value of setTimeout for
modern browsers and some old browsers for compatibility issues?
Definition and Usage. The setTimeout() method calls a function after a number of milliseconds. 1 second = 1000 milliseconds.
Browsers including Internet Explorer, Chrome, Safari, and Firefox store the delay as a 32-bit signed integer internally. This causes an integer overflow when using delays larger than 2,147,483,647 ms (about 24.8 days), resulting in the timeout being executed immediately.
First of all, the setTimeout JavaScript method should contain the function that you intend to apply. The second parameter sets a time when the specified function is to be called. However, it is optional, and the default value is 0.
Invoking setTimeout with a callback, and zero as the second argument will schedule the callback to be run asynchronously, after the shortest possible delay - which will be around 10ms when the tab has focus and the JavaScript thread of execution is not busy.
I think that 10 will be the most reliable minimum in all browser, since I've seen a lot of codes using it.
However, 4ms is the minimum for HTML5
In fact, 4ms is specified by the HTML5 spec and is consistent across browsers released in 2010 and onward. Prior to (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2) , the minimum timeout value for nested timeouts was 10 ms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With