Skip to content
Advertisement

False or None vs. None or False

JavaScript

This behaviour confuses me. Could someone explain to me why is this happening like this? I expected them to both behave the same.

Advertisement

Answer

The expression x or y evaluates to x if x is true, or y if x is false.

Note that “true” and “false” in the above sentence are talking about “truthiness”, not the fixed values True and False. Something that is “true” makes an if statement succeed; something that’s “false” makes it fail. “false” values include False, None, 0 and [] (an empty list).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement