Loose Equality (==)
noun
say it: “DUB-ul EE-kwulz” /ˈdʌbəl ˈiːkwəlz/ or “LOOSS ee-KWOL-ih-tee” /luːs iˈkwɒlɪti/
The == comparison in JavaScript: it converts the two values to the same type before comparing, so '7' == 7 is true. Most code uses === instead.
What is Loose Equality (==) in JavaScript?
Loose Equality (==) — The == comparison, read "loosely equal". When the two values have different types, it converts them first, so '7' == 7 is true, and the rules for those conversions surprise people. Use === unless you have a reason not to.
console.log('7' == 7); // true: the text is turned into a number
console.log('7' === 7); // false: text and a number
console.log(0 == ''); // true
In a sentence
- “Loose equality said the text '0' and the number 0 were equal, which surprised me.”
Level: Apprentice · More JavaScript terms at this level
Updated