Skip to main content

Posts

Showing posts with the label code style guide

Javascript Code Style Guide with examples

1.Variables, functions, properties methods: // Good var thisIsMyName; var anotherVariable; var aVeryLongVariableName; Methods: // Good function getName() { return myName; } // Bad: Easily confused with variable function theName() { return myName; } Constants: // Good eg: // Changing this value will be problem var MAX_COUNT = 10; var URL = "http://www.mydomain.net/"; if (count < MAX_COUNT) { doSomething(); } Global References:  // Note: Specify about below declaration,where they are used  var globalPreferedMode = false;  var globalUserPreferenceArr = [];  // Array used to compare with preference cols of trade grid while applying preferences 2. Single line comments: eg: // Good if (condition) { // if you made it here, then all security checks passed allowed(); } eg: // Good var result = something + somethingElse; // somethingElse will never be null Multiline comments: eg: // Good if (condition) { /* ...