Skip to content

Instantly share code, notes, and snippets.

@minitech
Last active December 10, 2015 02:58
Show Gist options
  • Save minitech/4371353 to your computer and use it in GitHub Desktop.
Save minitech/4371353 to your computer and use it in GitHub Desktop.
Why you shouldn’t pass an `undefined` to your wrapper.

A common pattern is to make sure that undefined is actually what it says it is, using some kind of wrapper function:

(function(undefined) {
    // undefined will be undefined now, even if some idiot overwrote it.
})();

Why you shouldn’t do that:

  1. Anyone who overwrites undefined on purpose gets all that’s coming to them.
  2. undefined is read-only in all modern browsers, and in strict mode, attempting to assign to undefined will throw an error. This does not apply to your local undefined variable; not a warning in sight. This is just a bug waiting to happen.

Avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment