0
(function (global, undefined) {
  ... some code which doesnt use arguments array
} (this));

I often see module pattern done in this way.

I really question why there's a second argument undefined? Are these examples buggy or is there a special meaning of undefined here?

lukas.pukenis
  • 11,459
  • 12
  • 42
  • 78

1 Answers1

2

undefined is a global property that is widely used. In older versions of JavaScript it is possible to change the value of it (for example, to true). This generally breaks everything. By changing its scope to be local to the "module" (i.e. the function), other modules are prevented from interfering with it.

This allows code to safely use undefined instead of having to use global.undefined.

MDN Reference

OrangeDog
  • 30,151
  • 11
  • 105
  • 177