not-defined
checks if foo is not defined, i.e. undefined, null, an empty string, array, object or NaN
Installation |
Usage |
License
Installation
npm install not-defined
Usage
This snippet of code
import notDefined from 'not-defined'
if (notDefined(foo)) {
}
is equivalent to the following pseudocode
if (foo is not defined, i.e. is null, undefined, NaN, an empty string, array or object) {
// do something, usually throw a TypeError
}
You can also use a shorter but still semantic form like
import no from 'not-defined'
if (no(foo)) {
}
Follows a list of tested examples
no()
no(undefined)
no(null)
no('')
no([])
no({})
no(NaN)
no(0)
no(true)
no(false)
no('string')
no(['foo'])
no({ foo: true })
no(42)
no(Infinity)
no(function () { return 1 })
Pros
- Type less.
- Better readability (even your boss will understand your code ^:).
- Can save bytes in your builds.
- Easier to autocomplete in editors (for instance easier than
typeof foo === 'undefined'
).
License
MIT