For those of you JavaScript/TypeScript coders who feel the ? :
operator is too mainstream, let me introduce you to an innovation I stumbled upon recently in our app's code, the && ||
operator:
return isOpen && "content/images/minus_menu.png" || "content/images/plus_menu.png"
(Note: isOpen
is a boolean variable)
Thanks to the wonder of truthy and falsy values in JavaScript, and the fact that in JavaScript &&
and ||
actually just mean "return my first or second operand, depending on the truthiness of the first operand", this abomination of logic that would cause Augustus DeMorgan to roll in his grave actually works as intended, as long as the second operand is never falsy.