Avoid Negative Conditionals

Negatives are harder to understand. Conditional functions should be expressed as positives every time.


☑️ Topic: Functions

☑️ Idea: Negatives are harder to understand. Conditional functions should be expressed as positives every time.

☑️ Benefits: Readability

☑️ Guideline: Function names should not have “not” in their name. Use the “not” Boolean operator with the function call instead.

// BAD
function isDOMNodeNotPresent(node) {
  // ...
}
if (!isDOMNodeNotPresent(node)) {
  // ...
}
 
// GOOD
function isDOMNodePresent(node) {
  // ...
}
if (isDOMNodePresent(node)) {
  // ...
}
// BAD
function isDOMNodeNotPresent(node) {
  // ...
}
if (!isDOMNodeNotPresent(node)) {
  // ...
}
 
// GOOD
function isDOMNodePresent(node) {
  // ...
}
if (isDOMNodePresent(node)) {
  // ...
}