Home > front end >  Arrange 1 ES6 grammar
Arrange 1 ES6 grammar

Time:12-15

1 ~ const/let
The console. The log (a)//undefined
var a=1;
The equivalent of
Var a;
The console. The log (a);
A=1;
Variable ascension is js when parsing, will first take statement variables mentioned in front, then the assignment, the assignment before printing a, rather then declare a, but there is no assignment. So it is undefined.
Let and const does not exist variable improve
The console. The log (a, b)
Const a=1;
Let b=1;//error: Uncaught ReferenceError: a, is not defined.

Const usually to declare a constant, and the constant address values cannot be changed
Const a=1;
A=2;
The console. The log (a)//an error
Const a=1;
B={};
B.a=2;
//1, the console. The log (a) not error
2 ~ template literal
Template literal used backquotes ` `
Var a='asd';
Var b='321';
Var c=` ${a} ${b} asdasdasd `
The console. The log (c)//asd321asdasdasd string concatenation


3 array


Let arr1=Array. The from ({
Zero: '1',
1: '2',
2:3,
Length: 3
})
The console. The log (arr1)//[" 1 ", "2", 3)

Let arr2=Array of (1, 2, 3, 4)
In the console. The log (arr2)//[1, 2, 3, 4].

//find usage
The console. The log (arr2. Find (item=& gt; Item> 3))//4 find greater than 3 Numbers in an array
//the fill usage, values, start the subscript, end the subscript
The console. The log (arr2. The fill (" modify the value of the ", 1, 2));//(1, "change the value of the", 3, 4]

FindIndex () method to return a test conditions (function) conforms to the condition of the first array element position;
FindIndex () method for each element in the array to invoke a function performs
If there is no qualified function will return 1, findIndex original value () will not change the original array and call for an empty array methods;

Var arr=,13,56,58 [12];
The function check (num) {
Return num> 56.
}
The console. The log (arr. FindIndex (check))//3

entries use to iterate over key/value pair
For (let (key, value) of [r]. 'a', 'b' entries ()) {
The console. The log (key, value)//0 "a" 1 "b"

}

keys () to iterate over the key value of
For (let the key of [' zhang ', 'bill', 'Cathy']. The keys ()) {
The console. The log (key)//0,
}

values () to iterate over the value and the keys () usage consistent


//includes () to find the object contains
Let arr4=Array of (' ht ', 'p', 'me')
The console. The log (arr4. Includes (' px))//true

//copy array
Let arr5=,2,5 [1],
Arr5 arr6=[...];
The console. The log (arr6)



Let [a, b, c]=[1, 2, 3]
The console. The log (a)//1
//not completely deconstruction
Let (s, d, f]=[1, 2];
The console. The log (s, f)//1 undefined
Can be nested
Let [a, [c] [b],]=[1, [[2], 3]]
The console. The log (a, b, c)//1, 2, 3

When deconstruction patterns have matching results and the results of the match when undefined; Will trigger a default value as the return result;

Let a=3, b=a]=[1, 2];
The console. The log (a, b)//1, 2

Object model of deconstruction
Let {aaa, BBB}={aaa: 'Joe Smith, BBB:' bill '};
The console. The log (aaa, BBB)//zhang SAN, li si

Nested
Let obj={p: [' hello '{y:' word '}]}.
{let {p: [x, y}]}=obj
The console. The log (x)//hello

//to deconstruct the default
Let {=10, b=5}={3} a:;
The console. The log (a, b)//a=3 b=5






  • Related