Hacker News new | ask | show | jobs
by locci 5446 days ago
I completely agree with you, but I would use "foo === undefined" for locals and "this/window.foo === undefined" for globals. You can also test for "== null", if you don't care for null values.

Of course due to a bug in the old (v3) spec, you could redefine the builtin undefined as well as some other builtins like NaN and Infinity, but you shouldn't really be doing that and the spec at least is now fixed.

In the meanwhile, to fight that, this is a commonly used pattern for browsers: (function(window,undefined) {

// code //

})(this);