Settings

Theme

The curious case of if-not

marcel.is

2 points by jugjug 5 years ago · 2 comments

Reader

baumandm 5 years ago

The two if statements given aren't logically equivalent; an equivalent version of the 2nd one would be:

  if (!(input.command === "foo" && isValid(input))) {
    ...
  }
Which IMHO is the least comprehensible.

You can flip the negation by swapping the if/else blocks, but only if there is an else. Then you also get into questions about whether or not it matters which block is on top.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection