JS Built-ins
TypeScriptbeginner

Type Guard β€” isNullOrUndefined

πŸ“– Usage Example
function isNullOrUndefined(x: unknown): x is null | undefined {
  return x === null || x === undefined
}
isNullOrUndefined(null)   // β†’ true
isNullOrUndefined(0)      // β†’ false

Check x === null || x === undefined to detect both nullish values precisely.

Type Guards: isNullOrUndefined

Challenge: Implement isNullOrUndefined(x: unknown): x is null | undefined.

isNullOrUndefined(null)      // β†’ true
isNullOrUndefined(undefined) // β†’ true
isNullOrUndefined(0)         // β†’ false
πŸ’‘ Hints (1)
  • β€’ Use strict equality (===) with both null and undefined.