isUndefined function
Checks whether a value is undefined; null does not pass.
ts
import { isUndefined } from 'utils';Signature
ts
export function isUndefined(value: unknown): value is undefinedParameters
| Name | Description |
|---|---|
value | The value to check. |
Returns
true for undefined only.
Example
ts
isUndefined(undefined); // true
isUndefined(null); // falseTests
Line coverage: 100 %.
- ✅ accepts undefined only
Source
src/guard/is-undefined.ts (on GitHub)
Source code
ts
/**
* Checks whether a value is `undefined`; `null` does not pass.
*
* @param value - The value to check.
* @returns `true` for `undefined` only.
* @example
* isUndefined(undefined); // true
* isUndefined(null); // false
*/
export function isUndefined(value: unknown): value is undefined {
return value === undefined;
}Test file
ts
import { isUndefined } from './is-undefined';
describe(isUndefined, () => {
it('accepts undefined only', () => {
expect(isUndefined(undefined)).toBe(true);
expect(isUndefined(null)).toBe(false);
expect(isUndefined(0)).toBe(false);
});
});Keywords: is, undefined, guards, function