JavaScript is designed to be very tolerant and flexible. Some of its features allow for code that is on the edge of the abyss, ready to break down at any time. Staying away from the most dangerous features and being conservative on those we use is a good insurance against pitfalls.
As any regular at the YUI forum can attest, many problems come from fragile code. Many a question could have been spared, and the time waiting for the answer saved, if the code had been clean. When our eyes are tired after a long session of coding and we are incapable of matching braces, there are programs that do the bean counting for us, checking that the parenthesis, braces, and brackets are matched, that lines have their semicolons and all those tedious tasks.
JSLint is a free JavaScript syntax analyzer available to use online at http://www.jslint.com and also available to run as a command-line utility in several environments or as a Yahoo! Widget (http://widgets.yahoo.com/, previously known as...