In Javascript, almost all expressions (all expressions?) have a "truthiness" value. If you put an expression in a statement that expects a boolean, it will evaluate to a boolean equivalent. For example:
let a = 'foo'
if (a) {
console.log('a is truthy!');
}
// Will print 'a is truthy!'.
In some workplaces it is common to coerce an expression in this situation into an actual boolean by negating it twice:
let a = 'foo'
if (!!a) {
console.log('a is truthy!');
}
// Will print 'a is truthy!'.
My question: Is this merely a matter of style? Is it purely to communicate to someone reading the code that we really recognize that a
is not a boolean, but that we intend to evaluate it as such anyway? Or do there exist any expressions or values of a
where if (a)
actually evaluates to a different boolean value than if (!!a)
?