Web Authoring - JavaScript
There are many tasks that can be accomplished by using JavaScript. Checking for pluginns, checking the browser being used and react accordingly, opening new customised windows, validating forms before the users submit them, calculations, calendars and a lot more. I have used several scripts in this site. The slideshow on the Photoshop page was made with JavaScript. Also, the disabling of the right-click on images so they can't be downloaded onto the visitor's hard drive has been done with JavaScript. It is a very powerful tool indeed and one that can give you some control and can provide a great interactivity for the users.
As with CSS, JavaScript coding can go within the <head> section, using the <script> tag, but I do like more using external .js pages for exactly the same reasons as with CSS, that is, freeing the HTML documents of as much coding as possible. By linking an external page, this is boldly achieved and it does exactly the same job. There will be times in which some bits of coding will have to go within the <body> tag, but that is just the way it is and, simply, unavoidable. It is not a big problem, however.
One of the problems with some scripts is that what works on one browser (Explorer, Firefox, Netscape...) sometimes does not necessarily work on all browsers, so it is important to understand that and test your scripts throughout all main browsers, and the Mac based browsers too, before you decide to implement them. Personally, and for accessibility reasons, if a particular script is not going to work on all main browsers, I would seriously consider to not use it, especially if the script is not absolutely necessary. Might be better trying an alternative or plan your page with a different approach.
The main point is, I think, when to use what, and seeing that it really helps your purpose as well as seeing that the scripts work fine across the browsers. Some people argue that Internet explorer -IE- browsers are widely used much more that any other, although not as much as it used to be. For that reason, they only plan and code looking into this particular browser reactions to the coding itself. And here I am not talking only about JavaScript, but also, CSS. The support for CSS also changes depending on the visitors browser. I do not like this approach, as it leaves out a considerable amount of people surfing the web using other browsers and they might land on your site only to see strange and weird reactions that most certainly would put them off and make them leave it without the information you intended to provide. For more on this, please check the Accessibility page on this site.