Type guard that checks whether a value is nullish (null or undefined).
null
undefined
The value to check
true if the value is null or undefined, false otherwise
true
false
if (isNullish(user)) { console.log('User is not defined');}const values = [1, null, 2, undefined, 3];const defined = values.filter(v => !isNullish(v)); // [1, 2, 3] Copy
if (isNullish(user)) { console.log('User is not defined');}const values = [1, null, 2, undefined, 3];const defined = values.filter(v => !isNullish(v)); // [1, 2, 3]
Type guard that checks whether a value is nullish (
nullorundefined).