Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!