I get the separation of layout and markup, I like MVC frameworks that separate code from layout but what about the JavaScript in a page? What are good patterns for separation of JavaScript from the layout? I know some things will need to be run before page load and will be embedded in the markup but what are good guidelines to follow?