The first thing you are going to confronted with upon creating a new project and opening on of the .js files is this structure.
This is a self or immediately executing function. It defines a function, then execute it. Nonsense! I hear you scream.
But if we define our variable in a self executing function. Then it does not.
Functions scopes are stacked, and the outer most layer of that stack is called the global scope. So consider a large application with hundreds of js files. If each of these files did not use the self executing function trick to get a local scope, then they would all share the global scope. Now consider how likely it is that two files would share a variable name and cause difficult to track down bugs.
It is interesting to note that Node actually wraps your modules in a function scope for you, so you get this safety out of the box.
I’ll try keep these posts short and to a single topic, so that will do it for this one. Next I am going to take a look at the WinJS.Namespace helper and show you how to use it to safely get objects back out of your function scope and into accessible globally.