In angular.js, there are some code snippets use !!
to check whether a value is truthy in if condition.
Is it a best practice? I fully understand in return value or other assignment !! is used to make sure the type is Boolean. But is it also true for condition checks?
if (!!value) {
element[name] = true;
element.setAttribute(name, lowercasedName);
} else {
element[name] = false;
element.removeAttribute(lowercasedName);
}
No,
!!
is totally useless in aif
condition and only confuses the reader.Values which are translated to
true
in!!value
also pass theif
test because they're the values that are evaluated totrue
in a Boolean context, they're called "truthy".So just use