Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Interval id counter keeps growing after clearing old one

Suppose I have the following intervals, the id of the first interval is 1, even that I cleared it the second interval gets id of 2. is there a way the I can reset the interval's id when it cleared? such that the second interval will have id of 1.

let it=setInterval(function(){
console.log(it);// prints 1
},1000);

clearInterval(1);

let it2=setInterval(function(){
console.log(it2); // prints 2
},1000);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

...is there a way the I can reset the interval's id when it cleared?

No. Every time you call setInterval or setTimeout, a new handle value is created. This is per specification. The only thing you can rely on about the handle is that, in the browser environment, it will be a whole number greater than 0 and won't be the same as any other timer handle that's been provided by previous calls in the same realm (roughly, on that page). (On Node.js it's not a number, it's an object.) (The fact it's never 0 is handy; you can use 0 as a "no timer is set" value for the handle variable.)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda