This is the sixth day of my participation in Gwen Challenge
ES6 (a)
let\const
- The difference between let and const is that let has a block-level scope. Var promotes a variable declared by var. Const is a constant and cannot be modified
Deconstruction assignment
All variables, arrays, and objects can be structurally assigned. A copy of a deconstructed assignment is a shallow copy. That is, if the value of a key is a value of a compound type (array, object, function), the deconstructed assignment copies a reference to that value, not a copy of that value.
let{ x, y, ... z } = {x: 1.y: 2.a: 3.b: 4 };
x / / 1
y / / 2
z // { a: 3, b: 4 }
// Destruct assignment must be the last argument, otherwise an error is reported.
let { ...x, y, z } = someObject; // Syntax error
let{ x, ... y, ... z } = someObject;// Syntax error
Copy the code
The use of template strings
let word = 'world'
let str = `hello ${word}`
Copy the code
String new method
Traditionally, JavaScript has only had the 'indexOf' method, which can be used to determine whether one string is contained within another. ES6 offers three new approaches. + **includes()** : Returns a Boolean value indicating whether the parameter string was found. + **startsWith()** : Returns a Boolean value indicating whether the argument string is at the head of the original string. + **endsWith()** : Returns a Boolean value indicating whether the argument string is at the end of the original string. [ES2019] (https://github.com/tc39/proposal-string-left-right-trim) for a new string instance ` trimStart () ` and ` trimEnd ` () these two methods. They behave in the same way as' trim() ', 'trimStart()' removes whitespace at the head of the string and 'trimEnd()' removes whitespace at the end. They all return a new string and do not modify the original string. , etc... A series of methods that are not commonly usedCopy the code
Extension of arrays
ES6 provides two new methods on Number objects: 'number.isfinite ()' and 'number.isnan ()'. 'number.isfinite ()' is used to check whether a Number isFinite(finite); 'number.isnan ()' is used to check if a value is' NaN '.Copy the code
Object extension
-
Properties and methods within objects provide a concise way to write them
-
Enumerability and traversal of properties
The description of the Object. GetOwnPropertyDescriptor method can obtain the attribute Object.
let obj = { foo: 123 }; Object.getOwnPropertyDescriptor(obj, 'foo') // { // value: 123, // writable: true, // enumerable: true, // configurable: true / /} Copy the code
An enumerable property that describes an object is called “enumerable.” If it is false, it means that some operations ignore the current property.
Currently, there are four operations that ignore enumerable as false.
for... in
Loop: Only the enumerable properties of the object itself and its inheritance are iterated over.Object.keys()
: returns the key names of all the enumerable properties of the object itself.JSON.stringify()
: Serializes only enumerable properties of the object itself.Object.assign()
: ignoreenumerable
forfalse
Only enumerable properties of the object itself are copied.
Of the four operations, the first three are available in ES5, and the last object.assign () is new in ES6