Type guard that checks if a value is null or undefined (nullish).
This function uses the loose equality operator (==) to check for both
null and undefined in a single comparison, which is the standard
JavaScript idiom for nullish checks.
Type Narrowing Behavior:
Narrows the input type to null | undefined when true
Useful for checking if a value is "nullish" (either null or undefined)
Parameters
u: unknown
The value to check
Returns uisnull|undefined
true if u is null or undefined, false otherwise. When
true, TypeScript narrows the type to null | undefined.
Type guard that checks if a value is
null
orundefined
(nullish).This function uses the loose equality operator (
==
) to check for bothnull
andundefined
in a single comparison, which is the standard JavaScript idiom for nullish checks.Type Narrowing Behavior:
null | undefined
whentrue