Type/Since
1.38.0isUndefined
Checks whether a value is exactly undefined.
isUndefined(value):value is undefinedBehavior
The function uses strict equality (===) to check whether the provided value is exactly undefined.
Undefined vs Null
Only undefined returns true. The value null is not considered undefined.
Type Guard
The return type is value is undefined, allowing TypeScript to narrow the value to undefined inside a conditional branch.
Parameters
valueunknownrequiredThe value to check.
Returns
value is undefinedReturns true when the value is exactly undefined; otherwise, returns false.
Examples
01
Basic usage
Check whether different values are undefined.
TypeScript
import { isUndefined } from "@cyref/js";
isUndefined(undefined);
// true
isUndefined(null);
// false
isUndefined(0);
// false
isUndefined("");
// false
isUndefined(false);
// false02
Type narrowing
isUndefined acts as a TypeScript type guard and narrows the value to undefined when it returns true.
TypeScript
const value: string | undefined = undefined;
if (isUndefined(value)) {
// value is undefined
}Built with@cyref/js·Official documentation