There are basically two approaches to this: Single Exit Point vs. Early Exit. I personally prefer the latter:
myFunction.getRange = function () {
if (this.settings.allowedValues) {
return {
min: Min,
max: Max
};
}
if (this.settings.range) {
return {
min: range[0],
max: range[1]
};
}
return {
min: 0,
max: 1
};
};
In this case it doesn't matter much, but real-life code with early exits (return
, break
etc) is easier to read and maintain than "single exit" one with many else
branches and temp variables.