Miscellaneous coding preference: return early rather than nesting business logic inside a conditional.
Bad:
function example() {
const optional = returnOptional()
if (optional) {
// all business logic,
// including additional nestings
}
// implicit `return undefined`
}
Good:
function example() {
const optional = returnOptional()
if (!optional) {
// explicit return value,
// good for clarity and intentionality
return null
}
// all business logic,
// starting at the top-level of nesting!
}