is.truthy
is.truthy(target: unknown)โ
The is.truthy
method is a utility function in JavaScript that checks whether a value is truthy or not. A truthy value is any value that is considered to be true
when encountered in a Boolean context. This includes not only the true Boolean value, but also values like non-empty strings, numbers other than 0, and objects.
The is.truthy
method returns true
if the value passed to it is truthy, and false
otherwise. It can be useful in many situations where you need to check whether a value is valid or not, or when you need to ensure that a certain condition is met before proceeding with a particular piece of code.
Overall, the is.truthy
method is a handy tool to have in your JavaScript toolbox, and can help you write more robust and reliable code.
Specificationโ
- Target argument: required.
- Checks if the given "target" type is true.
Informationโ
- Unit tests: โ
Examplesโ
is.truthy([]) // true
is.truthy('undefined') // true
is.truthy('null') // true
is.truthy(Symbol()) // true
is.truthy(true) // true
is.truthy(BigInt(1)) // true
is.truthy({}) // true
is.truthy(Function) // true
is.truthy(() => {}) // true
is.truthy(Bigint) // true
is.truthy(Symbol) // true
is.truthy(new Boolean(1)) // true
is.truthy(new Boolean(-1)) // true
is.truthy(false) // false
is.truthy(new Boolean(0)) // false
is.truthy(new Boolean()) // false
is.truthy(0) // false
is.truthy('') // false
is.truthy({}) // false
is.truthy([]) // false
// And all other known types will return false
Reversal boolean resultโ
is.not.truthy([]) // false
is.not.truthy('undefined') // false
is.not.truthy('null') // false
is.not.truthy(Symbol()) // false
is.not.truthy(true) // false
is.not.truthy(BigInt(1)) // false
is.not.truthy({}) // false
is.not.truthy(Function) // false
is.not.truthy(() => {}) // false
is.not.truthy(Bigint) // false
is.not.truthy(Symbol) // false
is.not.truthy(new Boolean(1)) // false
is.not.truthy(new Boolean(-1)) // false
is.not.truthy(false) // true
is.not.truthy(new Boolean(0)) // true
is.not.truthy(new Boolean()) // true
is.not.truthy(0) // true
is.not.truthy('') // true
is.not.truthy({}) // true
is.not.truthy([]) // true
// And all other known types will return true