Skip to content

isNil

Import from @varavel/vdl-plugin-sdk/utils/predicates.

function isNil(x): x is null | undefined;

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.

Parameters

Parameter Type Description
x unknown The value to test for null or undefined.

Returns

x is null | undefined

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

Example

const value1 = null;
const value2 = undefined;
const value3 = 42;
const result1 = isNil(value1); // true
const result2 = isNil(value2); // true
const result3 = isNil(value3); // false