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

219
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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