Skip navigation

Tag Archives: undefined

Learning experience with JavaScript is more excited day-by-day.

(function(undefined) {
    alert(typeof undefined);   // boolean
(function(undefined) {
    alert(typeof undefined);   // undefined

Refer jQuery source code (development version 1.7.1) and modernizr, the first line would be

(function( window, undefined ) {

})( window );
window.Modernizr = (function( window, document, undefined ) {

})(this, this.document);

To overcome the issue of undefined, these libraries passing undefined as local variable. Notice the third parameter is left blank.

Read my another post regarding the same topic.

I learned something interesting about JavaScript undefined. Here is the axioms and proofs.

  1. undefined is a type.
  2. undefined type has only one value. that values is undefined.
  3. There is a global variable called undefined
  4. global undefined variable has default value undefined
  5. global undefined variable is not a constant
  6. undefined is not a keyword
Proof (tested in firebug console)

1. typeof undefined \\undefined

2. undefined = 1; alert(typeof undefined !== 'undefined'); // false

3. var name = undefined;  \\ global variable undefined is assigned to name

4. alert(name); \\ undefined, that means undefined global variable has value undefined

5. undefined = 'rajakvk';  \\ we can change value

6. var undefined = 'rajakvk';  \\ no syntax error
    var if = 'rajakvk';  \\ SyntaxError: missing variable name

This gives very interesting findings and helps to understand strange JavaScript bugs.