2. Wrap your code in an anonymous self executing function. This keeps the variables in global scope to a minimum and reduces the possibility of clashes between different scripts you add to the same page.
// code goes here
// code goes here
var i, j, something;
5. Never use == or !=. While these can make your code one character shorter they are less efficient and less accurate than === and !== and they are more error prone to typos if you leave out an =. When comparing variables containing different types you should explicitly convert them to the same type for the comparison where you want that conversion to occur.
6. All form field values are strings. When a number is expected to be entered use Number() to convert the string to a number unless the number uses scientific notation in which case use parseFloat(). Never use parseInt() unless the number is being entered using a number base other than 10 (parseInt supports bases 2 though 36). Where the value is being used with subtraction, multiplication, or division then conversion is not needed. You can also use a unary + instead of Number().
7. Where ever possible use built in methods for processing instead of defining your own code. Where older browsers do not support the method use a polyfill so that new browsers can use the built in method and only the older browsers need to run extra code.
9. Use console.log() and the debugger built into your browser for debugging. There is no longer any reason to use alert(), confirm() or prompt() at all.
10. Internet Explorer 3 is long dead so there's no reason to pass a string as the first parameter to setTimeout() or setInterval() - more modern browsers expect that parameter to be a function.
11. Only use a "load" event where your script requires the entire page to have loaded before it can run. For example a script that substitutes for any image that failed to load needs to wait for the "load" event. A script that is displaying a slideshow does not need to wait.
This article written by Stephen Chapman, Felgall Pty Ltd.