For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/predicate/isNil.md.

isNil es-toolkit

Checks if a value is null or undefined.

const result = isNil(value);

Usage

isNil(value)

Use isNil when you want to check if a value is null or undefined.

import { isNil } from 'es-toolkit/predicate';

// null or undefined values
console.log(isNil(null)); // true
console.log(isNil(undefined)); // true

// Other values
console.log(isNil(0)); // false
console.log(isNil('')); // false
console.log(isNil(false)); // false
console.log(isNil([])); // false
console.log(isNil({})); // false

It can also be used as a type guard in TypeScript:

function processValue(value: string | null | undefined) {
  if (isNil(value)) {
    // value is now narrowed to null | undefined
    console.log('Value is empty');
  } else {
    // value is narrowed to string
    console.log(value.toUpperCase());
  }
}

Parameters

valueunknownrequired

The value to check if it's null or undefined.

Returns

Returns true if the value is null or undefined, false otherwise.

value is null | undefined
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.