Javascript - Kodstandard
1.1 Naming conventions
Use camelCase when naming variables, objects, functions, and instances.
Bad:
const OBJEcttsssss = {};
const this_is_my_object = {};
var my_name = "";
function c() {}
Good:
const thisIsMyObject = {};
function thisIsMyFunction() {}
var myName = "";
1.2 Blocks
Use braces with all blocks and put else on the same line as your if block’s closing brace.
Bad:
if( someVar )
{
name = someVar;
}
else
name = "Test";
Good:
if (someVar) {
name = someVar;
} else {
name = "Test";
}
2. Recommendations
Editor preferences:
- Use soft-tabs set to two spaces.
- No tabs allowed.
- Trim trailing white space on save.
- Set encoding to UTF-8.
- Add new line at end of files.