3 ms·
I was always instructed to use typeof when determining if a variable or property is undefined. Some attempts to access an undefined variable will result in an e
by deckar01 11y ago
I was always instructed to use typeof when determining if a variable or property is undefined. Some attempts to access an undefined variable will result in an exception being thrown.
http://stackoverflow.com/questions/27509/detecting-an-undefined-object-property http://stackoverflow.com/questions/27509/detecting-an-undefi...
- masklinn 11y agoThat's only a serious issue if the binding may not exist at all, which is an other way to say that it's only useful for global variables. A function parameter defines a binding by definition.
- deckar01 11y agoGood to know. I peeked into underscore's source to see how this type of check is handled. Aparently the issue is more complicated than I thought, because the following comparison is used: obj[key] === void 0 Are they really defending themselves against the function being rebound with undefined shadowed? http://adripofjavascript.com/blog/drips/javascripts-void-operator.html http://adripofjavascript.com/blog/drips/javascripts-void-ope...
- masklinn 11y agoYeah. It might be an issue when you're a widely used library, you might routinely encounter completely insane stuff. In a codebase you own though, I wouldn't worry about it, you can just set whoever decides rebinding undefined is funny on fire.