es-toolkit/docs/reference/predicate/isUndefined.md

35 lines
800 B
Markdown
Raw Normal View History

2024-04-25 14:56:13 +03:00
# isUndefined
Checks if the given value is `undefined`.
2024-04-25 14:56:13 +03:00
This function tests whether the provided value is strictly equal to `undefined`.
2024-04-25 14:56:13 +03:00
It returns `true` if the value is `undefined`, and `false` otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
## Signature
```typescript
function isUndefined(x: unknown): x is undefined;
```
### Parameters
2024-04-25 14:56:13 +03:00
- `x` (`unknown`): The value to test if it is `undefined`.
2024-04-25 14:56:13 +03:00
### Returns
(`x is undefined`): `true` if the value is `undefined`, `false` otherwise.
2024-04-25 14:56:13 +03:00
## Examples
```typescript
const value1 = undefined;
const value2 = null;
const value3 = 42;
console.log(isUndefined(value1)); // true
console.log(isUndefined(value2)); // false
console.log(isUndefined(value3)); // false
```