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