Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

21
  • 7
    Because if !! meant logical not, how would I turn 42 into 1? :) Commented Sep 30, 2019 at 6:15
  • 10
    Would ~~ then not have been more consistent for logical NOT, if you follow the pattern that the logical operator is a doubling of the bitwise operator? Commented Sep 30, 2019 at 6:24
  • 9
    First, if it was for consistency it would have been ~ and ~~ The doubling of and and or is associated to the short circuit; and the logical not doesn’t have a short circuit.
    – Christophe
    Commented Sep 30, 2019 at 6:55
  • 3
    I suspect the underlying design reason is visual clarity and distinction, in the typical use cases. The binary (that is, two-operand) operators are infix (and tend to be separated by spaces), whereas the unary operators are prefix (and tend not to be spaced).
    – Steve
    Commented Sep 30, 2019 at 7:01
  • 7
    As some comments have already alluded to (and for those who don't want to follow this link, !!foo is a not-uncommon (not not common?) idiom. It normalizes a zero-or-nonzero argument to 0 or 1. Commented Oct 1, 2019 at 1:02