Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
How to reset interval of set interval function

I'm wondering how to stop this function when next is not equal to targetVar and here's my code :

function detectChange(next,targetVar){
    if (next==targetVar){
        waktuSholat();
        console.log("Waktu Sholat Berhasil Di Perbarui");
    } else if (next!=targetVar){
        speakIt();
    }
}
setInterval(detectChange, 2000);

I don't know how to stop this interval. I really appreciate your help and your suggestion.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Store the id returned by setInterval and call clearInterval to stop it. Note that detectChange is called each time without any arguments, so both next and targetVar are always undefined; perhaps you meant to check global variables instead.

function detectChange(next,targetVar){
    if (next==targetVar){
        waktuSholat();
        console.log("Waktu Sholat Berhasil Di Perbarui");
    } else {
        speakIt();
        clearInterval(id);
    }
}
let id = setInterval(detectChange, 2000);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!