0
setTimeout(function(){...}, 100);

my question is can I remove 100 completely? If yes, what is the default value setTimeout receive in all modern browsers?

I had researched in 4 documents but can't find any for my question

w3schools says it is required but mozilla is not required and default value is 0, msdn and nodejs have nothing :)

  • I believe it will cast `undefined` to 0. – MinusFour Aug 27 '15 at 15:20
  • Why would you *want* to remove it completely? It defines how often the function should be called. – Scott Aug 27 '15 at 15:21
  • @Scott sometimes I just want to fix the problem of js execution that don't run if a function is called directly http://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful – superpan3000 Aug 28 '15 at 03:26

1 Answers1

2

As per the non normative W3C Recommendation (http://www.w3.org/TR/html5/webappapis.html#dom-windowtimers-settimeout)

handle = window.setTimeout( handler [, timeout [, arguments... ] ] )

handle = window.setInterval( handler [, timeout [, arguments... ] ] )

The 2nd argument (timeout) is optional and

  1. Let timeout be the second method argument, or zero if the argument was omitted.

the default value is 0.


However do note that

Note: Timers can be nested; after five such nested timers, however, the interval is forced to be at least four milliseconds.

Community
  • 1
  • 1
potatopeelings
  • 40,709
  • 7
  • 95
  • 119