Disallow Null Comparisons (no-eq-null)
Comparing to null
without a type-checking operator (==
or !=
), can have unintended results as the comparison will evaluate to true when comparing to not just a null
, but also an undefined
value.
if (foo == null) {
bar();
}
while (qux != null) {
baz();
}
Examples of correct code for this rule:
if (foo === null) {
bar();
}
while (qux !== null) {
baz();
}