Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jQuery file have two parameters in its function but receives only one parameter [duplicate]

Possible Duplicate:
How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?

I am trying to learn about js scopes and anonymous functions. I have tried to read the jQuery.js file and it looks like this:

(function( window, undefined ) {

...

}(window));

Why does it have in the function params undefined when no parameter is being passed to it when it is executed?

like image 343
Alon Avatar asked Jan 23 '26 20:01

Alon


1 Answers

This method is used so you can be sure that no one has previously redefined undefined value with something like

var undefined = true; 

or with other tricky/evil assignments outside the jQuery scoped function. So, inside that function every comparison done against undefined is safe.

like image 68
Fabrizio Calderan Avatar answered Jan 26 '26 11:01

Fabrizio Calderan