by thesimon · 8y ago · 0 comments
if (err) {
handleError(err)
return
}
and if (err) return handleError(err)
are equally good. The second one doesn't really make it clear wether handleError returns a value and that value is intended to be returned. if (err) return void handleError(err)
And in non-promise-based async JS, the return value is almost always lost/useless anyway so `return x` has no effect, might as well repurpose `return` for short-circuiting.So people reading this code may have to stop and puzzle out this little pattern.
Here you can replace “ void “ with a new line and have code anyone with basic familiarity with a c-like language can read and understand intuitively.
Even if it is, I definitely agree that it should only be done if you want to communicate that handleError's return value is meaningful and should bubble up.