All topics / Short-Circuit Evaluation

Short-Circuit Evaluation

Why && and || stop evaluating the moment the answer is already determined, and how that becomes both a useful coding pattern and a source of subtle bugs.

  1. Why bother checking the second half
  2. Where this becomes a real pattern
  3. The gotcha