Simple a useful 'tips' for write (much) better java script codeAlways pass your code in JSLINT
This is the most basic/best advice I can give you.
JSlint should be your 'compiler' for java script. It will catch so many bad coding behaviors that you want to bind it to your process and before committing any new code to your source control (you do use source control, right? :) you are passing the code there and fixing all the recommendations.
Use jQuery
"...jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript." or in the short version "Do more, write less".
It's so true in their case. Specially, if you aren't a JS guru, jQuery will give you the option to 'look' like one.
If you do need a nice widgets that aren't part of jQuery (e.g. Rich Text Editor) - I would go with YUI. There new version (3.0) is very well documented and they giving you lots of excellent tools to build on their widgets.
Always Use 'var'
Variables in java script 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.
It is a good idea to always declare global variables using 'var', but it is vital to declare function-scoped variables using 'var'.
Avoid 'eval'
The eval() function in javascript is a way to run arbitrary code at run-time. In almost all cases, eval should never be used. If it exists in your page, there is almost always a more correct way to accomplish what you are doing. For example, eval is often used by programmers who do not know about using Square Bracket Notation. Don't use it unless you are an experienced developer and know that your case is an exception.
Avoid 'with'
The 'with' statement in javascript inserts an object at the front scope chain, so any property/variable references will first try to be resolved against the object. This is often used as a shortcut to avoid multiple long references.
Use The + Operator To Type Convert To Number
In javascript, the + operator is used for both addition and concatenation. This can cause problems when adding up form field values, for example, since javascript is a non-typed language. Form field values will be treated as strings, and if you + them together, javascript will treat it as concatenation instead of addition.
To fix this problem, Javascript needs a hint to tell it to treat the values as numbers, rather than strings. You can use the unary + operator to convert the string value into a number. Prefixing a variable or expression with + will force it to evaluate as a number, which can then be successfully used in a math operation.
Example: +theform.elements["field1"].value // this will 'tell' the JS that its a number.
Avoid document.all
document.all was introduced by Microsoft in IE and is not a standard javascript DOM feature. Although many newer browsers do support it to try to support poorly-written scripts that depend on it, many browsers do not.

