Basically what you are asking about is called “Early return pattern” and yes, you can do that. This approach could be better in some situations. Let’s try to rewrite this function with it (keeping same functionality):
function updateRecords(records, id, prop, value) {
if (prop !== "tracks" && value !== "") {
records[id][prop] = value;
return records;
}
if (prop === "tracks" && records[id].hasOwnProperty("tracks")=== false) {
records[id][prop] = [value];
return records;
}
if (prop === "tracks" && value !== "") {
records[id][prop].push(value);
return records;
}
if (value === "") {
delete records[id][prop];
return records;
}
return records;
}
As you can see above using this pattern for current situation is not the best idea because it adds repetitiveness which breaks DRY principle.
To sum up, any pattern has it’s own up- and downsides and should be used mindfully.
For more detailed explanation please look here: