The logical OR
operator isn't commutative like +
, *
, etc. It returns the first expression which can be converted into true
. (Source Mozilla Doc)
In
false || undefined
,false
can't be converted totrue
by definition (since it's the opposite), so it returns the second operand (undefined
)In
undefined || false
,undefined
is a value, but considered asfalse
in Javascript, so the logical operator evaluate the second operand and returnsfalse
(because both operands are false).