Aller au contenu principal

isUndefined()

isUndefined(value): value is undefined

Checks if a value is undefined.

remarque

Only checks undefined, not null. Use isNil to check both.


Parameters

value: unknown

The value to check.


Returns: value is undefined

true if the value is undefined, false otherwise.


See Also


Since

1.0.0


Example

isUndefined(undefined); // => true
isUndefined(void 0); // => true
isUndefined(null); // => false
isUndefined(''); // => false
isUndefined(0); // => false

How it works?

Type guard that checks if a value is undefined.

Type Narrowing

Common Checks

ValueResult
undefined true
void 0 true
null false
0 false
'' false
false false

vs isNil


Use Cases

Detect missing properties 📌

Check if a value is strictly undefined. Essential for checking optional parameters or missing object keys.

if (isUndefined(options.verbose)) {
options.verbose = true; // Set default
}