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

  • Home
  • SEARCH
  • 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 8434167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:35:01+00:00 2026-06-10T06:35:01+00:00

myInterval = setInterval(function(){ MyFunction(); },50); function MyFunction() { //Can I call clearInterval(myInterval); in here?

  • 0
myInterval = setInterval(function(){
     MyFunction();
},50);

function MyFunction()
{
    //Can I call clearInterval(myInterval); in here?
}

The interval’s not stopping (not being cleared), if what I’ve coded above is fine then it’ll help me look elsewhere for what’s causing the problem. Thanks.

EDIT: Let’s assume it completes a few intervals before clearInterval is called which removes the need for setTimeout.

  • 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-10T06:35:03+00:00Added an answer on June 10, 2026 at 6:35 am

    As long as you have scope to the saved interval variable, you can cancel it from anywhere.

    In an “child” scope:

    var myInterval = setInterval(function(){
         clearInterval(myInterval);
    },50);
    

    In a “sibling” scope:

    var myInterval = setInterval(function(){
         foo();
    },50);
    
    var foo = function () {
        clearInterval(myInterval);
    };
    

    You could even pass the interval if it would go out of scope:

    var someScope = function () {
        var myInterval = setInterval(function(){
            foo(myInterval);
        },50);
    };
    
    var foo = function (myInterval) {
        clearInterval(myInterval);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty normal setInterval call (I think): var myInterval = setInterval(myFunction('passVar1', 'passedVar2'),
The issue is best explained by the code: var myinterval = setInterval(function() { $.ajax({
I have a function, that is called by interval function, as well on click
I have created simple script with setInterval function and it is working fine on
after mysql> select now() got 2012-03-29 14:07:10 if 5 minutes is my interval, so,
I have this code: It's very simple. I create an interval, and that works
I have a table with the following columns: contactId (int) interval (int) date (smalldate)
What I am trying to do is make a function that calls another function
For my game loop and certain animations I want to know the time interval
I have an interval that runs every 3 seconds to check for new data.

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.