is a shortcut to
(typeof foo === 'undefined') || (foo === null)
Installation | Usage | Annotated source | License
npm install not-defined --save
This snippet of code
var notDefined = require('not-defined')
if (notDefined(foo)) {
// do something, usually throw a TypeError
}
is equivalent to
if ((typeof foo === 'undefined') || (foo === null)) {
// do something, usually throw a TypeError
}
You can also use a shorter but still semantic form like
var no = require('not-defined')
if (no(foo)) {
// do something, usually throw a TypeError
}
- Type less.
- Better readability (even your boss will understand your code ^:).
- Can save bytes in your builds.
- Easier to autocomplete in editors.
This is my first npm package written using KISS Literate Programming. It is a very basic, plain ES5 function that is 73 characters long
module.exports=function(x){return (typeof x==='undefined')||(x === null)}