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

292
Visualizações
Can you explain why logical && in JavaScript returns the last operand in a statement if all operands are true, as opposed to returning boolean true

I am reading a really nice blog on logical and (&&) in javascript. javascript-and-or-logical-operators/

How logical and works

Starting from left and moving to the right, return the first operand that is falsy. If no falsy operand was found, return the latest operand.

his example

FALSY:

3 && 1 && 0 && 10; // => 0

I see that it returns 0, based on his explanation above. But why is that? Why isn't false returned instead. I realize that 0 is "falsy", so I would believe that the statement would now evaluate to boolean false? But I am not right, can you explain why?

he also presents this example

TRUTHY

true && 1 && { name: 'John' } => { name: 'John' }

I am confused again. Why does this statement return { name: 'John' } instead of returning true?

Thank you kind people for your patience in answering my question.

about 4 years ago · Juan Pablo Isaza
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