i would like to know if including javascript <script> within the header tag has any particular advantages or drawbacks. I've seen some sites with their <script> tags all place after the main page content but within the body tag. Also i've experienced cases where when you place the javascript code before the main page content it fails to run but when placed after, it does run. Just to clear the discrepancies!
Placing it in the header has the drawback of taking longer to load - stuff in HEAD is loaded after the DOM is built, stuff in BODY is loaded AS the DOM is built... since browsers can load more than one file at once, putting scripts inside BODY (typically right at the end) will start them downloading earlier in the process instead of waiting for the DOM to finish being built. Another advantage to placing it in BODY, particularly right before </body> is that anything in the markup before the SCRIPT tag will exist on the DOM, so you can start manipulating things on the DOM right then and there. This means in a LOT of cases where people wait for onload, you can get a head-start and just start making changes right then and there; adding events, adding elements that should only exist when scripting is on, class swaps -- and here's a cute one; any changes you make with element.style trumps any CSS that is applied later -- THOUGH you REALLY whenever possible should be doing class swaps and letting CSS do the heavy lifting instead of accessing element.style; though there are always exceptions. Most all the functionality of onload without the pain of detecting IE vs. RoW or relying on some fat bloated library nonsense. Loading the scripts and making changes before the stuff in HEAD is loaded has another advantage, it means any changes/additions to the document is applied BEFORE the CSS is applied. This cuts down on the layout 'jumping around' as much while changes are made. It's also advantageous if your scripts are enhancing markup instead of being in the markup; too many people bloat out their markup with scripting hooks like the various onevent attributes or having markup that only functions when scripting is enabled, instead of attaching their events and adding any extra scripting only elements from the script; it's why I think the scripting attributes should be deprecated, and many developers need to get their heads out of the "only works with javascript" mentality. Again progressive enhancement == graceful degradation == accessibility!