DEV Community

Discussion on: Code Tip: Avoid unnecessary else statements

willglyles profile image
willglyles • Edited on

Sometimes, yes. But generally, I don't agree. Omitting the else statement can be confusing to readers, especially if the if block has a fair amount of code (including other branches with return statements). I usually include the else statement for readability, except in trivial cases such as your example.

georgehanson profile image
George Hanson Author

Like anything it all depends. There are cases when it is useful and others where it is not. In a simple case like this, I think it reduces visual debt. But it's all up to the individual developer.