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.