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โ
| Value | Result |
|---|---|
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
}
true
false