Why does one reuse `undefined`?

javascript, jquery

Solution

Because in some JavaScript engines it's possible to set `undefined` to a value. This is to make sure `undefined` is really `undefined`.

Problem

In John Resig's slideshow on how he was building jQuery 1.4, he mentioned a point where he added an `undefined` variable to the jQuery closure because "we can re-use (the variable)". `undefined` is not an ordinary variable: ``` > var undefined = 4 undefined > undefined undefined ``` Therefore, we know that undefined is not a variable. So why would an `undefined` be re-undefined in the jQuery source?

Original source

Related problems