Skip to content Skip to sidebar Skip to footer

Can A Number Returned By Settimeout() In Javascript Be Negative?

Can a number returned by setTimeout() in javaScript be negative? Currently, I can see that the timeoutId's are 1,2,3,4,5,6.... in Chrome. In Firefox it starts from number 4 and so

Solution 1:

According to Mozilla

The returned timeoutID is a positive integer value

It uses a "pool" of ID's. They may or many not be released back to the pool (it's down to browser implementation - comments suggest they're probably not). To use them all up, you're going to have to do a lot of work and it's almost certainly a programming error.

Note that there is nothing in there to detail how those ID's are generated exactly, so it's not necessarily guaranteed that different browsers will start from the same number. The pool is also shared by setInterval which will effect the ID's.

Post a Comment for "Can A Number Returned By Settimeout() In Javascript Be Negative?"