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

169
Views
Is there a way to find out total number of times setInterval() executed for a particular function inside Javascript code using any command

I have a function say main() which uses setInterval(async()=>{ console.log("Hello")},1000). The function inside setInterval() is executed 13 times i.e. Hello is printing 13 times. I want to check the value or the number of time this setInterval is running. Is there any way to do that?

main(){
   setInterval(async()=>{
              console.log("Hello")
              await someApiCall();
              console.log("World");
              await anotherApiCall();
    },1000)
}

This main function can be called multiple times. Can that be causing the number of print statement to increase.

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

0

You can keep a track of it using some counter.

If you want to keep track of setInterval across multiple calls of the main function.

let count = 0;

const main = () => {
  setInterval(async() => {
    console.log("Hello")
    count++
    console.log(count)

  }, 1000)
}

main()
main()

If you want to keep track of setInterval within the main function.

const main = () => {
  let count = 0;
  setInterval(async() => {
    console.log("Hello")
    count++
    console.log(count)

  }, 1000)
}

main()

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!