There is a difference.
https://stackoverflow.com/questions/950 ... cript-file
If you put code directly in the action that you want to run later, you'll run into scope issues. Basically any var or function will be local instead of global as when run from a file. You can get around that by putting them inside a global variable. For example instead of
you could use
Then you can use foo any time later.