I have a few snippets of javascript scattered about my pages - many are contained in my own .js files, however some of the stuff that I\'ve found online sits directly on the
Generally there is no difference as indicated in the comments. But, if the snippet is embedded in the middle of the HTML in the page and it is not a function, it is executed immediately. Such script segments may have a difference in behavior when moved to a separate JS file when enough care is not taken.