Why both of these resolve to false:
console.log("potato" == false); //false
console.log("potato" == true); //false
Because what I know when using == loose comparison, JS coerces the operand. Since in JS, non-empty string should be true, why do above return false above ?
There needs a clarification about the
==operator. From ECMA-262 Section 11.9.3 the rule6, rule7 and later rule4 determines your resultIn your context,
falseandtruewill be converted to0and1, while the'potato'will be converted toNaN, the comparison expression’s value is alwaysfalse.Similarly, in
'' == truecomparison,''will be converted to0whiletruewill be converted to1, the expression isfalse.Due to the non-intuitive implementation of
==,===is encouraged to use in comparison.