Chinese original address
1. Use const rather than VAR for all references. This ensures that you cannot repeatedly assign values to references.
Let is used when a change reference is required.
Both const and let are block-scoped scopes.
2. How to create an object:
Const item = {};
Use shorthand for object properties, and group the attributes for shorthand.
3. How to create an array:
Const ARR = [];
Use Arr.push () to replace the direct assignment.
Use the extension operator to assign an array of values: Arrcopy = [... arr];
Use Array.from () to convert a class array object to a group:
const FOO = Document.queryselectorall ('. Foo ');
CONST nodes = Aarry.from (foo);
4. Deconstruction:
Use deconstructing to access and use multi-attribute objects:
function Getfullname ({firstName, lastName}) { return ' ${firstname} ${lastname} ';}
An array is also used to assign values:
Const ARR = [1, 2, 3, 4// equals first = Arr[0],second = Arr[1]
Use object deconstruction when returning multiple values: This does not care about the order of the attributes
function Returninput (input) { ... return {left, right, top, bottom}; = ProcessInput (input);
5.Strings
Use template strings instead of string links when programmatically generating strings
function Sayhi (name) { return ' How is You, ${name}? `;}
6. Functions
Using function declarations instead of function expressions
function foo () {}
The function expression that is called immediately:
() = { console.log (' Welcome to the Internet. Please follow me. ' );}) ();
Never declare a function in a non-function code block (if,while) and assign that function to a variable.
Let test; if (current) { = () = () = { ... };}
Do not use arguments, you can choose rest syntax ... Alternative. Rest is a real array, and you can specify the parameters you want to pass in
function cont (...args) { return args.join (');}
Specify default values directly to the parameters of the function, and do not use a variable function parameter
function fn (opts = {}) {...}
7. Constructors
Always use class to avoid direct manipulation of prototype.
Use extends inheritance.
Method can return this to help with chained calls.
Not finished
AIRBNB Javascript Code specification important points Summary Es6