Avoid Negative Conditionals

Avoid Negative Conditionals

Tags
Clean Code
Javascript
Software Development
Published
Published August 1, 2022
Author
Due Date
☑️ 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)) { // ... }