JavaScript naming conventions

peirix picture peirix · May 28, 2009 · Viewed 168k times · Source

I know there is a lot of controversy (maybe not controversy, but arguments at least) about which naming convention is the best for JavaScript.

How do you name your variables, functions, objects and such?

I’ll leave my own thoughts on this out, as I haven’t been doing JS for long (couple of years, only), and I just got a request to create a document with naming conventions to be used in our projects at work. So I’ve been looking (google-ing) around, and there are so many different opinions.

The books I’ve read on JS also use different naming conventions themselves, but they all agree on one bit: “Find what suits you, and stick to it.” But now that I’ve read so much around, I found that I like some of the other methods a bit better than what I’m used to now.

Answer

Geoff picture Geoff · May 28, 2009

I follow Douglas Crockford's code conventions for JavaScript. I also use his JSLint tool to validate following those conventions.