Skip to main content

isNonUndefined()

isNonUndefined<T>(value): value is T

Checks if a value is not undefined.

note

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


Type Parametersโ€‹

T: Tโ€‹

The defined type.


Parametersโ€‹

value: T | undefinedโ€‹

The value to check.


Returns: value is Tโ€‹

true if the value is not undefined, false otherwise.


See Alsoโ€‹


Sinceโ€‹

1.0.0


Exampleโ€‹

isNonUndefined('hello');   // => true
isNonUndefined(0); // => true
isNonUndefined(null); // => true (only checks undefined)
isNonUndefined(undefined); // => false

How it works?โ€‹

Type guard that checks if a value is not undefined.

Type Narrowingโ€‹

Common Checksโ€‹

ValueResult
nullcheckmark true
0checkmark true
''checkmark true
falsecheckmark true
undefinedcross false

vs isNonNullableโ€‹


Use Casesโ€‹

Verify definition ๐Ÿ“Œโ€‹

Strictly check that a value is not undefined (allows null). Useful for checking if a parameter was provided, even if it's null.

if (isNonUndefined(param)) {
// param was passed (could be null)
}