timeoutHandle = setTimeout(function() {
//code
},1000);
alert(timeoutHandle) returns me some strange numbers like 1 or 2, should it be sth like 900 and counting down to 0 when the function is called ? So I guess I’m doing this wrong.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
Date.getTime()to get aDateobject’s representation in milliseconds, so a (fairly accurate) approximation would be:The return value of
setTimeoutandsetIntervalis just a sort of “timer ID” – you use it to stop the timer withclearTimeoutandclearInterval, it doesn’t change dynamically.Edit: As @Rocket points out, yes, you can use
Date.now()instead ofnew Date().getTime().