In JS, you can define a function one of two ways – as a function literal, or a named function.

Function literal:

Named function:

While there are obvious difference as regards scope of garbage collection (e.g., a function declared with “var” within another function scope is local, and will be collected like any other variable). Since closures are the standard now anyways, the major difference is availability. A named function is available immediately, to all scopes.

That’s to say that this works fine:

While this does not, as the variable function is referenced before it’s defined: