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

102
Visualizações
javascript: memory difference of resetting a set variable?

Given the code:

function foo() {
  if (!this.isValid) {
    this.isValid = true; 
  }
}

and if I have foo() triggered by an resize event, is it any less efficient to do this:

function foo() {
  this.isValid = true; 
}

where it would be constantly setting this.isValid = true . The end result is the same but it's just resetting the variable over and over. Is there a difference memory wise to either one?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There wont be significant difference in both of them. As in the case of if, you ll have a comparison added. Incase of direct resetting of the value. you ll skip the comparison but the assignment operator will take up some time.
This can help for a cleaner code

function foo() {
   this.isValid = this.isValid || true; 
}
// so you value will not be overwritten
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