All code is in JavaScript, but the technique discussed is applicable to many languages.
50% of "else" statements are unnecessary. Not only that, they also increase bugs and decrease readability and maintainability. A coding technique to counter this is "guard clauses". Using them has the following benefits:
- Thinking in terms of guard clauses instead of if/else puts you in a frame of mind where you are more likely to catch bugs.
- This pattern increases code readability (and thus maintainability)
- It Keeps Code Left, which again increases readability