Type/Since
1.38.0isNull
Checks whether a value is exactly null.
isNull(value):value is nullBehavior
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
valueunknownrequiredThe value to check.
Returns
value is nullReturns 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("");
// false02
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