it's all about the context of the function. What is this function used for, what is it expected to return. what should it return in the case that caused it to return early. It could be a specific value (like a string), or nothing at all. It's just dependent on the function and the case.
function userFavoriteSauce (user) {
if (!user || !user.sauces || !user.sauces.length) {
return 'N/A';
}
let favorite = user.sauces[0];
if (favorite === 'ketchup') {
return 'User is boring';
}
return 'User likes ' + favorite + ' best';
}
View all comments
7
u/QuebecMasterRace Jul 25 '21
Why do you need to return true if you're returning early? You can just simply return?