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

272
Visualizações
What does the second line of the code mean?

please what does the second line of the following code mean, is it a tenary operation, if it's not then what is it and what does it mean

   const user = await User.findOne({ email: req.body.email });
   !user && res.status(404).json("user not found");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is not a ternary operator. The && operator is evaluating the left part, after coercing it to boolean if it is not. Then, if it turns true, it evaluates the right part after && and return the resulting value. But if it turns false, it returns the left part (not coerced).

The ! operator do two things : it coerces into boolean and returns the opposite value.

So here, if there is a user found in the first line, !user will be false and res.status(404).json("user not found") will not be evaluated.

If on the contrary no user was found, !user will be true and the second line will return a status 404.

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