Only variables declared without var become global, this does not apply to functions.
You can, however, declare foo like so:
foo = function() {}
and it should be global.
Omitting var is generally not recommended for these reasons (off the top of head):
- Variable resolution starts at the most local and goes toward looking in the global namespace, making it slower. Much slower in certain browsers.
- You tend to eventually have naming conflicts by polluting the global namespace. One of the worst offenders would be, say,
for(i = 0; i < arr.length; i++) (note the lack of var)
You might want to declare functions using var due to a language feature called hoisting
BTW, if you do choose to declare functions with var, I recommend you do so this way:
var foo = function foo() {}
because it gives the function a "name" instead of being treated as an anonymous function, which will help with debugging. Most people do not do this and declare using function, I believe.