Skip to main content

isUndefined()

isUndefined(value): value is undefined

Checks if a value is undefined.

note

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
undefinedcheckmark true
void 0checkmark true
nullcross false
0cross false
''cross false
falsecross 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
}