Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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. -
C0D4669024yfalse&&undefined
> Will return false as the first object is Falsey
true&&undefined
> undefined is Falsey and is returned as it's "false"
One does not do javascript and expect it to make sense - that's just asking for trouble. -
Damn you developers making sense of weird JS magic.
But that's kind of logical if you don't forget basic principles of boolean evaluation. -
everything 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
Related Rants
Okay I always found these js weirdnesses that you see in memes more or less logical if you think about it, but so far I could not find any logic behind this:
true&&undefined
>undefined
false&&undefined
>false
can anyone explain wtf they thought about there? undefined is falsy so why not just convert it to boolean implicitly!
rant
js
javascript