2024-04-25 14:56:13 +03:00
|
|
|
# isUndefined
|
|
|
|
|
2024-06-17 06:26:32 +03:00
|
|
|
Checks if the given value is `undefined`.
|
2024-04-25 14:56:13 +03:00
|
|
|
|
2024-06-04 11:19:26 +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;
|
|
|
|
```
|
|
|
|
|
2024-06-04 11:19:26 +03:00
|
|
|
### Parameters
|
2024-04-25 14:56:13 +03:00
|
|
|
|
2024-06-17 06:26:32 +03:00
|
|
|
- `x` (`unknown`): The value to test if it is `undefined`.
|
2024-04-25 14:56:13 +03:00
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
2024-06-17 06:26:32 +03:00
|
|
|
(`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
|
|
|
|
```
|