That's defining a scoping function and calling it immediately with some arguments. The purpose of a scoping function is largely to contain the things that are inside it to avoid creating globals.
So let's look at the arguments it passes:
window.pageName = window.pageName || {}
That will either pass the existing window.pageName
property, if it has a truthy* value, or a new object ({}
) if it doesn't, using JavaScript's curiously-powerful ||
operator, which results in its left-hand operand if that operand is truthy, or its right-hand operand if not. So within the scoping function, pageName
will always be truthy (and probably be an object).
jQuery
that's the non-$
variable for jQuery. Sometimes you need to use jQuery's noConflict
mode (which releases the $
global) to integrate with other libraries. So doing this lets you use $
within the scoping function knowing that it will be equal to jQuery
, even if $
outside the scoping function isn't.
Now about that third undefined
: Note that it never actually passes an argument to match that named argument. That means the value of the undefined
argument will be the value undefined
. This basically insures that the symbol undefined
within the scoping function really has the value undefined
(since until ES5 [~2009], you could overwrite it with some other value!).
* "truthy" - In JavaScript, a value is "truthy" if it coerces to true
when you use it as a boolean. Truthy values are values that aren't "falsey" (quelle surprise!). The falsey values are 0
, NaN
, null
, undefined
, ""
, and of course, false
.