Skip to content

Files

Latest commit

 

History

History
31 lines (23 loc) · 527 Bytes

no-negated-condition.md

File metadata and controls

31 lines (23 loc) · 527 Bytes

Pattern: Negated condition in control flow

Issue: -

Description

Using negated conditions makes code harder to understand. Improve readability by inverting the condition and swapping the consequent and alternate branches.

Examples

Example of incorrect code:

if (!a) {
  doSomethingC();
} else {
  doSomethingB();
}

!a ? doSomethingC() : doSomethingB();

Example of correct code:

if (a) {
  doSomethingB();
} else {
  doSomethingC();
}

a ? doSomethingB() : doSomethingC();