Search code examples
javascriptvalidationoperatorsconditional-operator

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


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.


Solution

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

    const validation = !flag && isValid;