-
Notifications
You must be signed in to change notification settings - Fork 1
JavaScript Coding Convention
A convention to standardize JavaScript coding style.
We are not reinventing the wheels. We adopt from AirBnB JavaScript Style Guide and adjust accordingly to our preferences.
In this document, we will rewrite the selected specification we adopt and add a few of our preferences. For anything that is not stated in this document, refer to AirBnB JavaScript Style Guide.
-
2.1 Use
constfor all of your references; avoid usingvar. eslint:prefer-const,no-const-assignWhy? This ensures that you can’t reassign your references, which can lead to bugs and difficult to comprehend code.
// bad var a = 1; var b = 2; // good const a = 1; const b = 2;
-
2.2 If you must reassign references, use
letinstead ofvar. eslint:no-varWhy?
letis block-scoped rather than function-scoped likevar.// bad var count = 1; if (true) { count += 1; } // good, use the let. let count = 1; if (true) { count += 1; }
-
3.1 Use the literal syntax for object creation. eslint:
no-new-object// bad const item = new Object(); // good const item = {};
-
3.3 Use object method shorthand. eslint:
object-shorthand// bad const atom = { value: 1, addValue: function (value) { return atom.value + value; }, }; // good const atom = { value: 1, addValue(value) { return atom.value + value; }, };
-
3.4 Use property value shorthand. eslint:
object-shorthandWhy? It is shorter and descriptive.
const lukeSkywalker = 'Luke Skywalker'; // bad const obj = { lukeSkywalker: lukeSkywalker, }; // good const obj = { lukeSkywalker, };
To be continued. More to come
Vision
Values
Forte
Organizational Structure
Proofhub
Web Design System
PHP Coding Convention