Compare `null` using `===` or `!==`

JavaScript pattern

Comparing to null needs a type-checking operator (=== or !==), to avoid incorrect results when the value is undefined.


Apply with the Grit CLI
grit apply no_eq_null

$val == null => $val === null

BEFORE
if (val == null) {
  done();
}
AFTER
if (val === null) {
  done();
}

$val != null => $val !== null

BEFORE
if (val != null) {
  done();
}
AFTER
if (val !== null) {
  done();
}

$val != null => $val !== null into while

BEFORE
while (val != null) {
  did();
}
AFTER
while (val !== null) {
  did();
}

Do not change $val === null

JAVASCRIPT
if (val === null) {
  done();
}

Do not change $val !== null

while (val !== null) {
  doSomething();
}