We use the double bang operator (!!) to check if a value is `truthy` or `falsy`.
That means to check if a value is considered `true` or `false` by JavaScript.
We use it when we need a boolean value according to a non-boolean value,
for example if we need the value `false` if a string is empty, `true` otherwise.
str = "Double bang operator";
console.log(str == true);
console.log(!!str);
str = "";
console.log(str == false);
console.log(!!str);
Truthy values :
- Objects : {}
- Arrays : []
- Not empty strings : "Anything"
- Numbers other than 0 : 3.14
- Dates : new Date()
Falsy values :
- Empty strings : ""
- 0
- null
- undefined
- NaN