It's about truthy and falsy:
Everything in JavaScript has an inherent Boolean value, generally
known as either truthy or falsy.
The following values are always falsy:
- false
- 0
- ""
- null
- undefined
- NaN
All other values are truthy, including "0" (zero in quotes), "false"
(false in quotes), empty functions, empty arrays, and empty objects.
In your case, I don't think it is useful, since an if
already uses the truthy/falsy value of the condition:
if (0) {
// this will never be executed
}
The !!
can be used like this:
return !!myObject.length; // returns true if myObject.length > 0, false otherwise