3

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?

2
  • 1
    It is already explained in here stackoverflow.com/questions/2716069/… Commented Sep 10, 2012 at 7:54
  • Read ScottLahteine's comment in response to the top answer to this question. It's to ensure that, within the method, the variable called undefined is genuinely undefined. Commented Sep 10, 2012 at 7:56

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.