I see some examples of multiple returns but don't see any guidelines defined that say it explicitly.
Is there a preference between a single return where a variable is assigned the output value vs just having multiple return statements?
function isGood(battery) {
if (battery.charge) {
return true;
}
if (battery.cycles < 10) {
return true;
}
return false;
}
vs.
function isGood(battery) {
let out = false;
if (battery.charge) {
out = true;
}
if (battery.cycles < 10) {
out = true;
}
return out;
}
I see some examples of multiple returns but don't see any guidelines defined that say it explicitly.
Is there a preference between a single return where a variable is assigned the output value vs just having multiple return statements?
vs.