I found two links that is really useful for javascript developers: http://www.javascripttoolbox.com/bestpractices/ and http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/e6ea1b73adfe8228.
These two links talk about best practices when developing javascript code.
1. Always Use 'var'
Variables in javascript either have global scope or function scope, and using the 'var' keyword is vital to keeping them straight. When declaring a variable for use either as a global variable or as a function-level variable, always prefix the declaration with the 'var' keyword.
2. Avoid 'with'
3. Use onclick In Anchors Instead Of javascript: Pseudo-Protocol
When you want to trigger javascript code from an anchor <A> tag, the onclick handler should be used rather than the javascript: pseudo-protocol. The javascript code that runs within the onclick handler must return true or false (or an expression than evalues to true or false) back to the tag itself - if it returns true, then the HREF of the anchor will be followed like a normal link. If it returns false, then the HREF will be ignored. This is why "return false;" is often included at the end of the code within an onclick handler.
4. Avoid document.all
Only Use document.all As A Last Resort
There is never a reason to use document.all in javascript except as a fall-back case when other methods are not supported and very early IE support (<5.0) is required.
5. Use Correct <script> Tags
The LANGUAGE attribute is deprecated in the <script> tag. The proper way to create a javascript code block is:
These two links talk about best practices when developing javascript code.
1. Always Use 'var'
Variables in javascript either have global scope or function scope, and using the 'var' keyword is vital to keeping them straight. When declaring a variable for use either as a global variable or as a function-level variable, always prefix the declaration with the 'var' keyword.
2. Avoid 'with'
3. Use onclick In Anchors Instead Of javascript: Pseudo-Protocol
When you want to trigger javascript code from an anchor <A> tag, the onclick handler should be used rather than the javascript: pseudo-protocol. The javascript code that runs within the onclick handler must return true or false (or an expression than evalues to true or false) back to the tag itself - if it returns true, then the HREF of the anchor will be followed like a normal link. If it returns false, then the HREF will be ignored. This is why "return false;" is often included at the end of the code within an onclick handler.
Correct Syntax
<a href="javascript_required.html" onclick="doSomething(); return false;">go</a>
What Not To Do
<a href="javascript:doSomething()">link</a> <a href="#" onClick="doSomething()">link</a> <a href="#" onClick="javascript:doSomething();">link&;lt;/a> <a href="#" onClick="javascript:doSomething(); return false;">link</a>
4. Avoid document.all
Only Use document.all As A Last Resort
There is never a reason to use document.all in javascript except as a fall-back case when other methods are not supported and very early IE support (<5.0) is required.
if (document.getElementById) { var obj = document.getElementById("myId"); } else if (document.all) { var obj = document.all("myId"); }
5. Use Correct <script> Tags
The LANGUAGE attribute is deprecated in the <script> tag. The proper way to create a javascript code block is:
<script type="text/javascript"> // code here </script>