Referencing Objects Before They are Loaded.
Javascript code that is placed in the head section of your page that is not contained within functions will be run before the page loads. Javascript in the body of the page will execute as that part of the page is loaded. Javascript called from the onload event handler will run after the page has finished loading. Functions will run when they are called from anywhere else in the Javascript code. Event handlers will run when the associated event is triggered.
If your Javascript is accessing the content of your web page via the document object model then those objects that you are referencing must have already loaded before you can reference them. Referencing an object that hasn't finished loading yet will give an error. To rectify this problem you should make sure that you don't try to reference any objects on the page from Javascript that is in the head section of the page unless it is contained in a function that gets called after the page finishes loading. References to objects from Javascript that is in the body of your page may work intermittently depending on the order in which the Javascript and the object that is referred to get loaded.
To rectify these problems move the processing of the object to the onload event handler for the web page.
Reserved Word Used as Variable Name
There are a number of words that have a special meaning to the Javascript language. These reserved words cannot be used as variable or function names. If you inadvertently use a reserved word as a variable name then the results of your processing will not be what you expect.
The best way to avoid this is to become familiar with the reserved word list so that you know what words to avoid. If you choose and follow an appropriate naming standard for your variable names you will be able to avoid using reserved words as variable names because your standard naming convention will make sure that they don't get used.
