简体   繁体   中英

setTimeout and setInterval's second param is required? if not, what is the default value?

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM