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

108
Visualizações
Why does an undefined operand not return false?

Given the following:

let a;
let b = false;
let c = a && b === undefined;

In my understanding, undefined is a falsy value, so why is it that c has value undefined instead of false?

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

0

c ends up undefined because a is undefined. The && operator stops with the first value that's falsy through a process called short circuiting

about 4 years ago · Juan Pablo Isaza Relatório

0

Given your example, a is undefined. Therefore, a && ... is undefined && ..., and since undefined is falsy, the left hand side short circuits. That means, it never evaluates the right hand side.

If the left hand side is falsy, there's nothing the right-hand side of an && can do to change that. To use an analogy, false && anything always evaluates to false, and in JavaScript, it stops there and ignores anything.

Now, the question may be, "Why doesn't it return false instead of undefined?" MDN says:

The logical AND operator, &&

If the first object is falsy, it returns that object

false && "dog" // ↪ false

0 && "dog" // ↪ 0
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