I can't claim to write good Javascript, I haven't been using the language that long. However, I have come across some good guidelines that help me keep things clear.
First, take a look at the
Google Javascript Style Guide. It's got some pretty good guidelines. Always run your code through
JSLint, it's strict and it can keep your code in shape.
Actually, Douglas Crockford's
Code Conventions for the JavaScript Programming Language is a very important read. I think it's more clear than Google's hints.
Finally, I think the most important guideline is:
do not pollute the global namespace. It's ridiculously easy to do that in Javascript, and the consequences aren't always clear. I don't particularly enjoy using
the module pattern, but it works.
These are just my initial observations from a couple of months of using the language, if anyone has some other insights and corrections please feel free to share.