Skip to content

isFalsy

Checks if a value is falsy (false, null, undefined, 0, "", NaN).

Available since v2.0.0

import { isFalsy } from '@helpers4/guard';
// or, from the all-in-one package (same code, one install):
import { isFalsy } from 'helpers4/guard';
isFalsy(value: unknown): value is Falsy
ParameterTypeDescription
valueunknownThe value to check

value is Falsy — True if the value is falsy

Returns true for all falsy values: false, null, undefined, 0, "", NaN.

isFalsy(0)         // => true
isFalsy('')        // => true
isFalsy(null)      // => true
isFalsy('hello')   // => false

Union of all falsy types in JavaScript. Note: NaN cannot be represented as a type in TypeScript.

type Falsy = false | null | undefined | 0 | ''

View source on GitHub