Reputation: 217
Code inspection (IntelliJ and GitHub) says that the following code can be simplified:
type Something = string | number | boolean | object
function isSomething(a: unknown): a is Something {
return a != undefined && a != null;
}
because a != null
is always true
. Why is that? AFAIK undefined
and null
are different values.
Upvotes: 0
Views: 139
Reputation: 26324
a != undefined
is false if a
is null. That means if a
is null
, the second condition will never run, since the &&
operator will short-circuit.
console.log(null == undefined); // true
console.log(null != undefined); // false
Upvotes: 3