What if we pass that function to something other than set Timeout?
Now the function expression we are passing to "do Stuff" has access to "A" and even after "outer Function" finishes "A" will remain in memory for as long as there is a reference to the function we passed into do Stuff. "my Function" will be cleaned up only if "do Stuff" does not hold a reference to it and "A" will only be cleaned up when "my Function" is cleaned up.
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.
My rule of thumb is that if the function is more than 2 lines of code, it probably belongs in it's own definition.
I really don't care what the other guy does if it doesn't cause pain but I try to always name my funcs because it's not hard and it can be an advantage.If you use an inline function expression then it is often useful to name it anyway for the purposes of debugging or code clarity.Memory leaks Whether you name your function, use a function statement, or use a function expression has little impact on the memory leak issue. Take a look at this code: In this code (above) the function expression we are passing to set Timeout has a reference to "A" (through the magic of closure) and even after "outer Function" finishes "A" will remain in memory until the timeout is triggered and the function is dereferenced.Named functions There is some serious misuse of terminology in the question and answers on this page.There is nothing about whether or not a function is inline (a function expression) that says you cannot name it.
//an example where you wold prefer to use an anonymous function.