Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  1] [ 1]  / answers: 1 / hits: 39247  / 12 Years ago, mon, april 9, 2012, 12:00:00

I was curious that what does setTimeout return. So I did a quick test:



var thing = setTimeout(function(){},1);


And what surprise me is that it gave me a number. 1351 Each time is different.



So is it really all it returns is a number? So I can actually do this as well?



clearTimeout(1351);


Very confusing...


More From » javascript

 Answers
34

It's a handle (a unique identifier). When you create a timeout, the JavaScript runtime associates a handle with the timeout you created, and it can identify that timeout by the handle setTimeout() returns. When you run clearTimeout(), it will know what timeout you're talking about by looking at the unique handle you pass in.


[#86365] Friday, April 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaredsages

Total Points: 273
Total Questions: 97
Total Answers: 105

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
jaredsages questions
;