Within an if condidition, when does it make sense to use a double negation? I found this pattern several times:
JS
if(!!children.length) { ...}
Within an if condidition, when does it make sense to use a double negation? I found this pattern several times:
JS
if(!!children.length) { ...}
It's a common method to turn a normal expression to a boolean. It doesn't really make any sense inside an if
statement, since it evaluates the given expression as a boolean anyways, but is useful outside.
For example:
const isEmpty = !!children.length;