Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is minimum millisecond value of setTimeout?

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?

like image 402
jwchang Avatar asked Mar 10 '12 14:03

jwchang


People also ask

Is setTimeout in seconds or milliseconds?

Definition and Usage. The setTimeout() method calls a function after a number of milliseconds. 1 second = 1000 milliseconds.

Is there a limit to setTimeout?

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.

What is the default value of setTimeout?

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.

What happens when setTimeout 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.


1 Answers

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.

like image 164
Martin. Avatar answered Oct 06 '22 03:10

Martin.