Function explanation

I ve a bit of missunderstood about functions: as i read the functions works:

basically 2 types:
named (can be lonely)
unamed (need and object)

  • can i define a function wherever i want? ( _root, MC…) and call it from everywhere?, before or after i created it?

  • if the variables of a function are local variables of that function. How can i store the result of a calculation of the function, in a variable outside it?

apologize my poor english
Regards!