Should logical operators always return booleans? #3415
gwhitney
started this conversation in
Design decisions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently they do. But in many languages,
and
of a number of arguments returns the first "falsy" argumen, or the last argument if they are all "truthy", whereasor
of a number of arguments returns the first "truthy" argument, or the last argument if they are all "falsy". Here "falsy" means "converts to boolean false" and analogously for "truthy". For example,2 or false
would return2
under this alternate convention. This alternative version of the logical operators can be very useful for producing concise formulas that filter out bad values, avoiding ternaries likex ? x : false
and the like. If there was interest in adopting a revised convention, it would be a breaking change, but it would be convenient to implement it along with fixes to #3414.Beta Was this translation helpful? Give feedback.
All reactions