Loose Equality (==)
Loose equality (==) can convert operands of different types before comparing them. It is not simply strict equality with a convenience feature.
Unexpected equality often comes from a conversion you did not make visible.
See the mechanism
trueFollow one example
These results are true, true, true and false. null and undefined have a special loose-equality relationship; null is not loosely equal to every numeric value that another operation might convert it into. Prefer === for ordinary checks and explicitly convert validated input where required.
Predict, change and check
Predict: Can you infer null == 0 from Number(null) being 0? Which rules does each operation use?
Test your explanation: Run Number(null) alongside null == 0. Explain why conversion in one operation is not a universal replacement rule.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
A rule with cases, not a numeric shortcut
The loose comparison algorithm first considers operand types and has special branches. null == undefined is true, but null == 0 is false even though Number(null) is zero. Do not substitute one conversion operation into a different comparison operation and assume the result is preserved.
If a product deliberately accepts both string and numeric identifiers, normalize that boundary under a documented schema instead of applying == everywhere. Objects can invoke conversion behavior during loose comparison. Strict equality is usually easier to reason about when both operands are already expected to have the same type.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.