not
description
Returns the logical negation of the input value. It's the functional equivalent of the JavaScript not operator !
. It can be very useful in a function composition chain, to avoid writing code like this:
As you can see from the type signature, it obviously accepts Booleans
as input values, but also values of any types. Just beware of how JavaScript coerces values to their Boolean equivalents.
examples
basic example
usage in a function composition
Suppose we want have a function which checks if an input string is valid. The input is considered valid if does not contain any illegal characters. The illegal characters are listed in a regular expression. Then, we use RegExp.prototype.test
to see if any of these characters is matched in the input string. Since our input is considered valid only if it searchIllegalCharacters
returns false, we use the logical not operator to negate its result.
Last updated