CyrefJS
CCyrefJS
فا
Back to documentation
Type/Since 1.38.0

isNull

Checks whether a value is exactly null.

isNull(value):value is null

Behavior

The function uses strict equality (===) to check whether the provided value is exactly null. Unlike a loose null check, undefined is not considered null.

Type Guard

The return type is value is null, allowing TypeScript to narrow the value to null inside a conditional branch.

Parameters

valueunknownrequired

The value to check.

Returns

value is null

Returns true when the value is exactly null; otherwise, returns false.

Examples

01

Basic usage

Check whether a value is null.

TypeScript
import { isNull } from "@cyref/js";

isNull(null);
// true

isNull(undefined);
// false

isNull(0);
// false

isNull("");
// false
02

Type narrowing

isNull acts as a TypeScript type guard and narrows the value to null when it returns true.

TypeScript
const value: string | null = null;

if (isNull(value)) {
  // value is null
}
Built with@cyref/js·Official documentation