1. New declaration commands let and const
In ES6, we use let for variables and const for constants. (1) Let and const are both block-level scopes. Scoped with {} blocks can only be used within blocks. (2) There is no variable promotion, can only be declared before use, otherwise an error will be reported. Within a code block, a variable is not available until it is declared. This is grammatically known as a "temporal dead zone" (TDZ). (3) In the same code block, do not allow repeated declarations. (4) Const is a read-only constant and is assigned when declared. If const is an object, the value of the object can be modified. To put it more abstractly, the address to which an object points cannot be changed, whereas variable members can be changed.Copy the code
2. Differences between arrow functions and ordinary functions
(1) Arrow functions are anonymous and cannot be used as constructors. You cannot use new (2) arrow functions instead of binding arguments to rest... (3) The scope of this is different. Arrow functions do not bind this and capture the this value of the context in which they are located as their own this value. (4) Arrow functions do not have primitive propertiesCopy the code
3. Deconstruct assignment
ES6 allows you to extract values from arrays and objects and assign values to variables in a pattern called Destructuring. The value in the array is automatically resolved to the corresponding variable that receives the value. The value of the array must correspond one by one. If there is a mismatch, the value of the array is undefined. The elements of an array are arranged in order, and the value of a variable is determined by its position. The attributes of an object have no order, and variables must have the same name as the attributes to get the correct value.Copy the code
4. Promise objects
(1) Promise is a solution for asynchronous programming. Asynchronous operations are expressed in the flow of synchronous operations, avoiding layers of nested callback functions. (2) It is in three states: pending, resolved, and rejected. (3) The Promise constructor contains an argument and a callback with resolve and reject. Perform some operation (asynchronous, for example) in the callback, calling resolve if all is well, reject otherwise. You can call the promise.then() method on an already instantiated Promise object, passing the resolve and reject methods as callbacks. The then() method takes two arguments, onResolve and onReject, which represent the current Promise object when it succeeds or fails.Copy the code