Congratulations! You've found the situation where Function Hoisting gets involved.
var foo = function() { };
is quite different than
function foo() { };
For all the reasons noted elsewhere, plus one.
The second example will be "hoisted" - it will be available anywhere within the current closure (usually the current function). Even before it's declared within said closure.
Something like this would work:
function foo() {
bar();
function bar() { alert('baz'); }
}
Whereas something like this would most definitely not:
function foo() {
bar();
var bar = function bar() { alert('baz'); };
}
You get an error in this second example, because bar has not been defined yet. If you swap the two lines in the function foo, that example will work.
Douglas Crockford advocates using this second method, because it doesn't contain a hidden behavior like hoisting - your code does exactly what it says it'll do, no tricks involved.