This kind of code can be confusing for beginners when they start coding:
function doSomething() {
if (somethingElseHappens())
return;
// ...
}
How would you explain this in a real life scenario that could tell how/why this is useful?
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