Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:18:20+00:00 2026-06-01T18:18:20+00:00

Just found this code-snippet in our application. I am wondering if the first line

  • 0

Just found this code-snippet in our application. I am wondering if the first line is superfluous — does one need to call clearTimeout on a variable if it is immediately overwritten? Or is there some condition I should be aware of?

function Countdown() {
    clearTimeout(sessionTimeoutHandle);
    sessionTimeoutHandle = setTimeout(function () { countdownHandler() }, MILLISECONDS);
}

My hunch is “Yes, you need to call clearTimeout” because I can’t think of why the clearTimeout method would exist if it was OK to just set the timeout variable to null.

I suppose the better question is:

var timeoutHandler = setTimeout(countdownHandler, MILLISECONDS);
timeoutHandler = setTimeout(countdownHandler, MILLISECONDS);

Do I now have two functions waiting to fire in approximately MILLISECONDS, or just one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:18:21+00:00Added an answer on June 1, 2026 at 6:18 pm

    No, you only need to call it if you actually need to clear it.

    If this is the only code using that variable, then there should be no need.


    FYI, it looks like you could shorten the code a bit…

    function Countdown() {
        clearTimeout(sessionTimeoutHandle);
        sessionTimeoutHandle = setTimeout(countdownHandler, MILLISECONDS);
    }
    

    Nothing was gained with the anonymous function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found my code like this does not compile right? Is there any
I just recently found myself writing this line of code, which i did not
I've just found in my java project this code snippet: List<IssueType> selectedIssueTypes = new
Hey all, I am completely lost on this one. I found a code snippet
I found this code snippet here , but I just can't figure out what
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression
I have just found this great tutorial as it is something that I need.
I just started a new Typo3 4.6 site and I found this weird line
I found this nice snippet of code online: rkApp = Registry.LocalMachine.OpenSubKey(SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run, true); Which runs
I found this snippet: def timesince(dt, default=just now): now = datetime.utcnow() diff = now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.