2024-06-04 11:19:26 +03:00
|
|
|
# isNil
|
2024-04-25 14:56:13 +03:00
|
|
|
|
|
|
|
Checks if a given value is null or undefined.
|
|
|
|
|
2024-06-04 11:19:26 +03:00
|
|
|
This function tests whether the provided value is either `null` or `undefined`.
|
2024-04-25 14:56:13 +03:00
|
|
|
It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
|
|
|
|
|
|
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
2024-06-04 11:19:26 +03:00
|
|
|
function isNil(x: unknown): x is null | undefined;
|
2024-04-25 14:56:13 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import { isNil } from 'es-toolkit/predicate';
|
|
|
|
|
|
|
|
const value1 = null;
|
|
|
|
const value2 = undefined;
|
|
|
|
const value3 = 42;
|
|
|
|
const result1 = isNil(value1); // true
|
|
|
|
const result2 = isNil(value2); // true
|
|
|
|
const result3 = isNil(value3); // false
|
2024-06-04 11:19:26 +03:00
|
|
|
```
|