News for hackers. Stuff that matters.
Re:Using the switch(true) pattern in JavaScript by tsimionescu on Monday April 12, 2021 @03:51PM (#26784272)
Never ever use if without curly braces. That's one of the worst ideas of C's syntax.

Your first example would still look clean like this:

  function check(x) {
      if (!test1 (x)) { return false; }
      if (!test2 (x)) { return false; }
      if (!test3 (x)) { return false; }
      if (!test4 (x)) { return false; }
      return true;
  }
And it would be much safer from stupid copy/paste errors.

There are no comments on this comment yet.