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