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

275
Vistas
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 Respuestas
Responde la pregunta

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