Skip to main content
Version: Next

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