DEV Community

Discussion on: if (!_if) what

 
mahlongumbs profile image
Mahlon Gumbs

Sure. The example is a bit contrived. There would definitely be more error handling logic, as you've mentioned.

Help me understand what you mean by "denseness". From my pov, things look basically the same if you ignore the coding style.

const wow = arg => {
  return (
    animals.hasOwnProperty(arg) && animals[arg]
      || "gimme an animal";
  );
};

vs

const wow = arg => {
  if(animals.hasOwnProperty(arg)){ //WTF if, who invited you?
    return animals[arg];
  }
  return "gimme an animal";
};
Thread Thread
 
alainvanhout profile image
Alain Van Hout • Edited

I’m mostly referring to the fact that it’s a single versus two separate statement/expressions, with the corrolary that the latter allows a line of whitespace inbetween to emphasize them being separate concerns. Moving the second part of the A || B to the next line aids the separation a bit, most people tend to not do that unless the total statement/line is too long to fit.

Edit: thanks for the interesting discussion btw

Thread Thread
 
mahlongumbs profile image
Mahlon Gumbs • Edited

Ah...ok. Understood. I agree.

edit: Absolutely. That's what this is all about. Thanks for the feedback.