DEV Community

Discussion on: ✔||🤢 Commit or Vomit | nested ternary operator

Collapse
 
tominflux profile image
Tom

If you stumble across something like this in a large codebase when you need to get something implemented/fixed quickly, it's a bloody nightmare.

Takes ages to grasp the context of what this kind of code is trying to do. It's always worth putting each sub-condition in a named boolean constant.
e.g. const doesProfileExist = ...

And then using a fail-fast if statement straight after.
e.g. if (!doesProfileExist) return x