2

I noticed my colleagues are writing code with double negation in conditions, for example:

else if(colType == 'link'){
    value = !!data ? $(data).attr('href') : '';
}

In cases like this, is there a chance that the boolean result of data can be different from !!data?

  • In that specific case, no, there's no difference whatsoever between `!!data ?` and `data ?`. See the linked question's answers for details. You only need the double bang (`!!`) when you need the result to be a boolean (`true` or `false`), specifically, not when just having truthy/falsy is good enough. – T.J. Crowder Aug 04 '17 at 06:38

0 Answers0