Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
True is truthy, and since this is an and operation we need to check every part of it. The last part to be checked is undefined
False is falsy, and since it's an and operation we know it won't be true no matter what the following parts are, so we can just stop at false.
> Will return false as the first object is Falsey
> undefined is Falsey and is returned as it's "false"
Katakompe36446dDamn you developers making sense of weird JS magic.
But that's kind of logical if you don't forget basic principles of boolean evaluation.
halfflat226946dAs in C-like languages, && and || short-circuit: the second argument will only be evaluated if the first one is true (respectively, false).
But like Perl and unlike C, they return the last value they had to evaluate, not true or false. Which is very handy in try-this-or-else-this-or-else-this type expressions.
theabbie54125deverything in JS can be evaluated as boolean, So, if you use any variable in a conditional operation it will be evaluated as TRUE if it's defined and FALSE if it's undefined (unless they are actually boolean variables), So, In your case, undefined is same as false, hence, the output