Let's consider what we should be trying to achieve by adding JavaScript to our web pages and the correct way of creating our pages to make them as user friendly as possible. Let's also look at a number of JavaScript commands that you may find still in use in a lot of the scripts that you might obtain from various script repositories that while they may still work at the moment are definitely not what you want to use for developing your scripts for the future.
There are a lot of old web pages around that use outdated ways of attaching their JavaScript into their web pages. Often these pages break for those visitors with JavaScript disabled. A lot of them also use browser sensing to attempt to work out what browser a given visitor is using and then make assumptions as to what JavaScript that browser supports. Since most of those scripts were written when version 4 browsers were the most recent the assumptions that those scripts make are mostly wrong.
A lot of people who are new to JavaScript seem to concentrate on how they can add JavaScript to their page to try to restrict what their visitors can do. This is just about the complete opposite of what you should be using JavaScript for.
Your web page should be accessible for people to use even if they have JavaScript turned off. If they do have JavaScript enabled then your JavaScript code should enhance the site and make it easier for them to use.
Using JavaScript the right way will encourage your visitors to return to your site in the future while using it the wrong way may drive them away never to return. Since you presumably want people to visit your site it is extremely important that your JavaScript be written in such a way that it encourages rather than discourages visitors.
JavaScript the Old Way
Several years ago you could be fairly sure that everyone accessing the internet was doing so using computers. Those computers were using screens set to either 640 x 480 or 800 x 600 resolution and almost everyone viewed web pages with their web browser maximized. Most people were also running early versions of web browsers which didn't properly support stylesheets and which had their own custom JavaScript commands for interacting with the web page.
Back then the only way of setting out the way that you wanted your web page to appear was to set up a primitive grid layout using a table. Fortunately the limited range of browser window sizes made this a reasonably practical option.
The lack of standard ways of linking your JavaScript to the appropriate parts of the web page meant that you needed to embed a significant portion of the JavaScript code into the actual page itself in order to get it to work at all. A lot of JavaScript code was also needed to determine which browser your visitor was using in order to run the appropriate JavaScript commands that the particular browser could understand.