My rule of thumb is that if the function is more than 2 lines of code, it probably belongs in it's own definition.This is complicated by most example code making use of Anonymous functions. The method falls apart as things get more complicated.I define it outside of a function and I want to change the global variable value from inside a function and use it from another function, how do I do this?Just reference the variable inside the function; no magic, just use it's name.Named functions There is some serious misuse of terminology in the question and answers on this page.
Sometimes inline make the code easier to read, sometimes harder. Anonymous function refs are quick, but should only be used for simple stuff.
This is using a function expression: If the name is specified (the text after "function" but before the parenthesis) then it is a named function regardless of whether it is inline or declared separately. points out that IE mishandles named function expressions in a non-trivial way (See: and this is important to note, I'm simply trying to make a point about the terminology. In response to your direct question, you should use a named function statement if the function could ever be used from any other place in your code.
If the name is not specified then it is "anonymous". If the function is being used in exactly one place and has no relevance anywhere else then I would use a function expression unless it is prohibitively long or otherwise feels out of place (for style reasons).
Named functions are also absolutely necessary if you ever get into Test Driven Development.
I am using Java Script and I create a global variable.