Are there any coding standards for JavaScript?

JavascriptCoding Style

Javascript Problem Overview


What are the established coding standards for JavaScript?

Javascript Solutions


Solution 1 - Javascript

Not exactly what you're looking for, but (like Doug Crockford's vids) I think everybody who writes/edits/reviews JS should look at Chris Heilmann's slides and videos on maintainable javascript.

In the slides, slide 127, he says don't worry so much about style guides/code standards, reformat all code checked in to VCS.

Also these:

Mozilla JavaScript Tips

JavaScript Style Guide

Solution 2 - Javascript

Another reason why Crockford's JavaScript coding guidelines are a good idea to follow:

This code (below) actually returns undefined because of JavaScript's semicolon injection - which is a damn good reason to get the whole team of developers singing from the same song sheet:

return // injected semicolon, therefore returns 'undefined'
{
	javascript : "fantastic"
}; // object constructs anonymously but nothing happens with it.

Bit more about that at Beware of JavaScript semicolon insertion

Solution 3 - Javascript

I never saw a widely acknowledged JavaScript coding standard out there. We did write our own some time ago and I published it on my blog in accordance with my employer.

Keep in mind that some of the guidelines might be a bit outdated.

Solution 4 - Javascript

Google has posted a Javascript guide

Solution 5 - Javascript

You can find some simple but essential coding conventions at the Google Code Wiki.

For very detailed style guides read the Dojo Style Guide. It is going over naming conventions, file conventions, variable usage, code layout, whitespace, and comments.

Solution 6 - Javascript

A bit puzzled that I cannot find on the replies Idiomatic.js and jQuery Core Style Guide. Addy Osmani puts those two on the very top of full list of coding styles for JavaScript in his "JavaScript Style Guides And Beautifiers" article.

I personally prefer jQuery standard, though it doesn't much differ from Idiomatic.js. But whatever standard you choose you will need a validator to check how successful you are following it. I couldn't find any for jQuery or at least Idiomatic, but eventually came up with JS_CodeSniffer

Solution 7 - Javascript

The comp.lang.javascript Code Guidelines document points to causes of errors and problems related to javascript for web applications and how to avoid them.

Solution 8 - Javascript

Myself and a few others recently put together these (PDF or HTML)

They are primarily intended for use with the Ajax Control Toolkit but realistically contain all sorts of useful guidance whichever framework you use.

Hope that helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPafjoView Question on Stackoverflow
Solution 1 - JavascriptGene TView Answer on Stackoverflow
Solution 2 - JavascriptRemy SharpView Answer on Stackoverflow
Solution 3 - JavascriptLBugnionView Answer on Stackoverflow
Solution 4 - JavascriptPedroView Answer on Stackoverflow
Solution 5 - JavascriptaemkeiView Answer on Stackoverflow
Solution 6 - JavascriptDmitry SheikoView Answer on Stackoverflow
Solution 7 - JavascriptGarrettView Answer on Stackoverflow
Solution 8 - JavascriptSimonView Answer on Stackoverflow