0

I read recently that setTimeout()'s timeout limit is 2147483647.

When I set the timeout to 2147483648 the program changes it to 1 but doesn't do when the timeout is set to 52147483648.

setTimeout(() => console.log(2147483648), 2147483648) // will fire in 1ms
setTimeout(() => console.log(52147483648), 52147483648) // will fire in a long time

What is happening here?

Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • 1
    Please may you add a [mcve] to the question demonstrating the issue? – evolutionxbox May 26 '21 at 09:51
  • 3
    Does this answer your question? [Why does setTimeout() "break" for large millisecond delay values?](https://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values) – Antonio Erdeljac May 26 '21 at 09:57

2 Answers2

0

Maximum delay value 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.

settimeout

shangzhouwan
  • 246
  • 1
  • 6
0

As per the Documentation, the setTimeOut Function supports a maximum of 24.8 days [MDN Ref] that is equal to 2147483647

Thus when you do 2147483648 you essentially get is (2147483648 - 2147483647 = 1)

However, when you use 52147483648 as per the epoch time converter this is only 17 days ahead in the future which is less than 24.8 days thus it does not convert it

Nishant S Vispute
  • 713
  • 1
  • 7
  • 21
  • Thanks but I want to know this section, how is it: "However, when you use 52147483648 as per the epoch time converter this is only 17 days ahead in the future which is less than 24.8 days thus it does not convert it" – kadrinadri May 26 '21 at 10:16
  • See if this help you undetstand the convertion https://www.epochconvert.com/programming/javascript#:~:text=Get%20Epoch%20or%20Unix%20Timestamp%20in%20JavaScript,getTime()%3B – Nishant S Vispute May 26 '21 at 10:36