Home > Mobile >  How is the better way to resolve a ternary that if true return false?
How is the better way to resolve a ternary that if true return false?

Time:08-18

I have a flag that could be true or false that is validating a ternary, then the if true return false otherwise return any value from variable.

const validation = flag ? false : isValid;

This validation seems weird, I want to know if exists another way to improve this validation.

CodePudding user response:

Your code seems clear to me, but if you want another way to write it:

const validation = !flag && isValid;
  • Related