mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-18 13:31:31 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
689 B
689 B
isNil
Checks if a given value is null or undefined.
This function tests whether the provided value is either null
or undefined
.
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
function isNil(x: unknown): x is null | undefined;
Examples
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