// for ES6 allows to extract the value of the variable assignment and from an array of objects according to a certain pattern which is deconstructed the let [A, B, C] = [l, 2,3] // pattern matching let [foo, [[bar] , baz]] = [. 1, [[2],. 3 ]] foo // . 1 bar // 2 baz // . 3 the let [head, tail ...] = [1,2,3,4 ]; head // . 1 tail // [2,3,4] the let [X, Y, Z ...] = [ 'A' ]; X // 'A' Y // undefined instructions deconstruction is unsuccessful undefinded Z // [ ] // incomplete deconstruction mode i.e. the left operand pattern matching only the right portion of the array equals i.e. incomplete deconstruction let [x, y] = [ 1,2,3] X // . 1 Y // 2 // the Set array structures may also be used destructuring assignment of the let [X, Y, Z] = new new the Set ([ 'A', 'B', 'C' ]) X // ' A ' // destructuring assignment means allowing to specify a default the let [foo = to true ] = [] foo // to true the let [X, Y =' B '] = [' A ' ] X // ' A ' Y // ' B '
const [a, x, c, s, a] = 'hello'; // destructuring assignment is to convert the string into a string array-like object A @ H X E // C // L // array-like the object has a length property so you can also deconstruct assignment to this property
// const declare a read-only constant value once declared constants can not be changed should not the same as when the assignment and var const // declare variables can not be changed because you must declare the beginning otherwise it will error // const only in the same scope and let variable block-level scope statement is declared effective nor upgrade there are also temporary dead zone // const value guaranteed not inherently variable not alter the memory addresses but variable points to the saved data may not change // for complex data variables stored at the memory address is just a pointer to the actual data can only be guaranteed const // pointer is fixed (i.e., an address is always fixed point) const foo = {} foo.prop = 123; Console. log (foo.prop); // foo = {} // foo constants as given storage address is an address that points to an object is immutable this address is not the address of this point // points to another address, but the object itself variable data structure attributes can be added const a = []; a.push ( 'Hello') a.length = 0; // a = [ 'Dave'] // array given supra changed console.log ( A); const = fooo Object.freeze ({}); // frozen object fooo.prop = 123; // normal mode may be given the strict mode is newly added property does not work // object completely frozen function var Constan = (obj) => { Object.freeze (obj); Object.keys (obj) .forEach ((Key, I) => { IF (typeof obj [Key] == 'Object') { Constan (obj [Key]) } }) }
// ES5 only two ways to declare variables // 1.var command // 2.function command // ES6 declare variables method: // 1.var // 2.let // 3.const // 4.class // 5.function command // 6.import command // property of the top-level object // browser environment middle window object // the Node middle finger global objects // properties var function declaration ES6 global variables still belong to the top-level object (for the and ES5 compatible) // but let global variables declared const class no longer belongs to the top-level object attributes // globalThis object // browser window self is the top object also points to top-level object // the Node in the top-level object is a global