Skip to main content
Version: 2.0.3

is.falsy

is.falsy(target: unknown)โ€‹

The is.falsy method is used to determine if a value is falsy, meaning it evaluates to false when coerced to a boolean. Falsy values include false, 0, null, undefined, NaN, and the empty string ''.

The is.falsy method takes a single argument and returns a boolean value indicating whether the argument is falsy or not. If the argument is falsy, the method returns true. Otherwise, it returns false. The is.falsy method can be useful when checking if a value is null or undefined, or when checking if a value has been initialized. It can also be used in combination with other is methods to create complex type checks.

Note that the is.falsy method does not check for empty arrays or objects. To check if an array or object is empty, you can use the is.emptyArray and is.emptyObject methods, respectively.

Specificationโ€‹

  • Target argument: required.
  • Checks if the given "target" type is false.

Informationโ€‹

  • Unit tests: โœ…

Examplesโ€‹

is.falsy(false) // true
is.falsy(new Boolean(0)) // true
is.falsy(new Boolean()) // true
is.falsy(null) // true
is.falsy(undefined) // true
is.falsy(0) // true
is.falsy(-0) // true
is.falsy(NaN) // true
is.falsy("") // true
is.falsy('') // true
is.falsy(``) // true

is.falsy(true) // false
is.falsy(new Boolean(1)) // false
is.falsy(new Boolean(-1)) // false
is.falsy({}) // false
is.falsy([]) // false
// And all other known types will return false

Reversal boolean resultโ€‹

is.not_falsy(false) // false
is.not_falsy(new Boolean(0)) // false
is.not_falsy(new Boolean()) // false
is.not_falsy(null) // false
is.not_falsy(undefined) // false
is.not_falsy(0) // false
is.not_falsy(-0) // false
is.not_falsy(NaN) // false
is.not_falsy("") // false
is.not_falsy('') // false
is.not_falsy(``) // false

is.not_falsy(true) // true
is.not_falsy(new Boolean(1)) // true
is.not_falsy(new Boolean(-1)) // true
is.not_falsy({}) // true
is.not_falsy([]) // true
// And all other known types will return true