DEV Community

Discussion on: Explain Empty Returns Like I'm Five

Collapse
 
cjbrooks12 profile image
Casey Brooks

It's really nice in validation functions, where certain conditions must be met before proceeding. By returning early (maybe with a log about why), you keep the validation logic entirely flat. The alternative is making a deeply nested set of checks that are even more difficult to understand, since deep nesting makes it more difficult to know which lines of code are related