Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda