I have a for of loop where I need to exit if there are no resulting values. It occurs to me that I could use an early return statement to handle this, or use a break statement. To be clear, in this case, there is no additional code to execute WITHIN this block of code after the part I'm skipping, so I'm assuming either one would work here (break or return). Any functional or performance reason to use one over the other in this particular case?
OPTION 1: (break)
for (let diff of differences) {
if (!diff.path) break;
if (diff.path[0] !== "updatedAt") {
const docChange = new ChangedProp(doc, diff, lastEditedBy, "customer");
docChange.log();
}
}
OPTION 2: (return)
for (let diff of differences) {
if (!diff.path) return;
if (diff.path[0] !== "updatedAt") {
const docChange = new ChangedProp(doc, diff, lastEditedBy, "customer");
docChange.log();
}
}
breakwould probably be the better choice.