r/backtickbot • u/backtickbot • Mar 23 '21
https://np.reddit.com/r/learnjavascript/comments/mb6zey/assigning_default_value/grwvrpf/
i think it should be very clear what getImagePath returns so we just make sure it's gonna return a string or null and then the long version becomes this:
const getImagePath = () => return 'path_to_image.jpg' || null;
const path = () => {
const imagePath = getImagePath();
if (!imagePath) {
return 'default.jpg';
}
return imagePath;
}The short version is good.
1
Upvotes