Back to Functions

isNil

lang

Checks if value is null or undefined.

Installation

Import
import { isNil } from '@tulx/utils';

Source Code

Implementation
/**
 * Checks if value is null or undefined.
 *
 * @param value - The value to check.
 * @returns Returns true if value is nullish, else false.
 *
 * @example
 * ```ts
 * isNil(null); // true
 * isNil(undefined); // true
 * isNil(NaN); // false
 * ```
 */
export function isNil(value: unknown): value is null | undefined {
  return value === null || value === undefined;
}

Example

import { isNil } from '@tulx/utils';

isNil(null); // true
isNil(undefined); // true
isNil(NaN); // false

Related Functions