So, a junior programmer on my team today wrote the following piece of code:
if(status === (\"incomplete\" || \"unknown\"))
Which is obvious
In JavaScript, the ||
operator returns its first operand if it evaluates to true
(i.e. it is not false
, null
, undefined
, ""
, or 0
), and its second operand otherwise.
In the first case, ("incomplete" || "unknown")
always evaluates to "incomplete"
, since it evaluates to true.
The entire condition then becomes:
if (status === "incomplete")
Which explains the behaviour you are observing.