"normal" function declarations are hoisted to the top of the scope, so they're always available.
Variable declarations are also hoisted, but the assignment doesn't happen until that particular line of code is executed.
So if you do var foo = function() { ... }
you're creating the variable foo
in the scope and it's initially undefined
, and only later does that variable get assigned the anonymous function reference.
If "later" is after you tried to use it, the interpreter won't complain about an unknown variable (it does already exist, after all), but it will complain about you trying to call an undefined
function reference.