Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  159] [ 2]  / answers: 1 / hits: 51184  / 14 Years ago, thu, august 12, 2010, 12:00:00

I came across some unexpected behavior when passing a large millisecond value to setTimeout(). For instance,



setTimeout(some_callback, Number.MAX_VALUE);


and



setTimeout(some_callback, Infinity);


both cause some_callback to be run almost immediately, as if I'd passed 0 instead of a large number as the delay.



Why does this happen?


More From » settimeout

 Answers
5

This is due to setTimeout using a 32 bit int to store the delay so the max value allowed would be



2147483647


if you try



2147483648


you get your problem occurring.



I can only presume this is causing some form of internal exception in the JS Engine and causing the function to fire immediately rather than not at all.


[#95937] Tuesday, August 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diane

Total Points: 264
Total Questions: 104
Total Answers: 95

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;