mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-18 13:31:31 +03:00
2df38fe4e2
* docs: add inline code markdown
* fix: change to undefined[] annotation
* Revert "fix: change to undefined[] annotation"
This reverts commit 3b81b8fb8a
.
* chore: recommit
35 lines
800 B
Markdown
35 lines
800 B
Markdown
# isUndefined
|
|
|
|
Checks if the given value is `undefined`.
|
|
|
|
This function tests whether the provided value is strictly equal to `undefined`.
|
|
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
|
|
|
|
- `x` (`unknown`): The value to test if it is `undefined`.
|
|
|
|
### Returns
|
|
|
|
(`x is undefined`): `true` if the value is `undefined`, `false` otherwise.
|
|
|
|
## 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
|
|
```
|