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

220
Vistas
Why should we not explicitly assign undefined to a variable in javascript?

I have heard it in some videos and blogs that we should not assign undefined to a variable in JavaScript explicitly in our code, instead we should use null. Why though?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

My conclusion is that undefined, lets us know that a variable has not been initialized yet, if we initialize it in our code and then make it undefined at a later stage, then it would lose its purpose hence we should use null, instead.

There can be a case, in which your logic dictates that if you get an undefined variable then the flow should be different than the case wherein you get null.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Undefined indicates a very specific use case. It means that the value is not initialized, and you don't know what the value is. The problem is you would not want to get "undefined" as an output while working with your code unless it indicates a problem that is tied up to the lack of assignment. Null, NaN, and empty values all indicate the lack of a value rather than the lack of assignment, which is usually the desired behavior.

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