Last active
October 2, 2015 20:28
-
-
Save 1337/2314040 to your computer and use it in GitHub Desktop.
Far fewer things to hate about JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* http://javascript.crockford.com/code.html | |
| JavaScript code should not be embedded in HTML files unless | |
| the code is specific to a single session. | |
| */ | |
| // All variables should be declared before used. | |
| var sampleVar; // Avoid lines longer than 80 characters. | |
| var stupidFunction = function (param1, param2, param3, // There should be no space between the name of a function and the (, except If a function literal is anonymous | |
| param1) { // There should be one space between the ) and the { | |
| var varOne; // comment about this variable // Generally use line comments. Save block comments for formal documentation and for commenting out. | |
| var varUno; // comment about this variable // align comments | |
| var varUne = []; // comment about this variable // Use {} instead of new Object(). Use [] instead of new Array(). | |
| varUne[1] = 4; // Use arrays when the member names would be sequential integers. | |
| while (true) { // one space after keywords | |
| if (1 === 1) { // it is almost always better to use the === and !== operators | |
| // Avoid doing assignments in the condition part of if and while statements. | |
| } | |
| } | |
| return true; // A return statement ... should not use () around the value. The return value expression must start on the same line as the return keyword in order to avoid semicolon insertion. | |
| }; // The } is aligned with the line containing the beginning of the declaration of the function | |
| <script src="filename.js"> tags should be placed as late in the body as possible. | |
| There is no need to use the language or type attributes. It is the server, not the script tag, that determines the MIME type. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment