To == or to ===
In general I would always advise you to use the Strict Equals Operator or === whenever you do a comparison unless you have a specific need for the behavior or the original operator.
What is the problem with ==
I mentioned that == has problems and should be avoided but its still helpful to understand these problems. These problems basically boil down to the fact that the == operator does type conversions if the two types being compared are not the same. For example the following all evaluate to true:
1: 0 == "0" // true
2: 1 == "1" // true
3: 2 == "2" // true
Sounds reasonable enough right?
Unfortunately it isn’t quite that simple all of the following evaluate to false:
1: false == "false" // false
2: true == "true" // false
These might seem weird, especially since the following evacuates to true again:
1: true == !!"true" // true
The Abstract Equality Comparison Algorithm
1: 0 == 0 // true
2: 1 == 1 // true
3: 2 == 2 // true
So what was the case in the other two comparisons?
In these cases almost the same happens and the Boolean values are converted to a number. That leaves a number to string comparison where the string is also converted to a number. And the result of converting true and false to a number is 1 and 0 but the result of the string to number conversions is an invalid number or NaN. And NaN being not equal to any other number means those comparisons result in false.
So why did the last comparison true == !!”true” evaluate to true? Well simple the double bang operator !! is evaluated first and a non empty string is truthy. End result of that is the expression true == true and that is obviously true. Sounds reasonable but that also means that any non empty string will result in true, so even true == !!"false" evaluates to true 🙁