Skip to main content
Version: 1.0.2

is.boolean

is.boolean(target: unknown)โ€‹

The is.boolean method checks whether a given value is a boolean or not. It returns true if the value is either true or false, and false otherwise.

This method can be useful when you need to ensure that a particular variable or parameter in your code is a boolean, and you want to avoid unexpected behaviors that could result from passing a non-boolean value to a function or method that requires a boolean.

Instead of writing your own implementation of this method, you can use the is.boolean method provided by the thiis package, which has been thoroughly tested and is a reliable solution for checking boolean values.

To use the is.boolean method, simply import it from the thiis package and pass the value you want to check as an argument:

By using the is.boolean method from the thiis package, you can ensure that your code is more reliable and easier to maintain, since you're relying on a well-tested and widely-used implementation of this functionality.

Specificationโ€‹

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

Informationโ€‹

  • Unit tests: โœ…

Examplesโ€‹

is.boolean(true) // true
is.boolean(false) // true
is.boolean(new Boolean()) // true
is.boolean(new Boolean(0)) // true
is.boolean(new Boolean(1)) // true

is.boolean(0) // false
is.boolean('') // false
is.boolean({}) // false
is.boolean([]) // false
// And all other known types will return false

Reversal boolean resultโ€‹


//
is.not.boolean(true) // false
is.not.boolean(false) // false
is.not.boolean(new Boolean()) // false
is.not.boolean(new Boolean(0)) // false
is.not.boolean(new Boolean(1)) // false

is.not.boolean(0) // true
is.not.boolean('') // true
is.not.boolean({}) // true
is.not.boolean([]) // true
// And all other known types will return true