This is the 11th day of my participation in the August More Text Challenge
Write in front:
- This article is used as a summary of my study, and to share with you ~
- Personal front-end blog website: Zhangqiang.hk.cn
- Welcome to join the blogger front-end learning QQ exchange group: : 706947563, focus on front-end development, learning and progress together!
- let & const
Let and const are block-level scopes and are recommended instead of var.
Differences: Let can be reassigned. Const cannot be reassigned. So we usually use const when we define a variable with a fixed value.
let arr = [];
const today = 'Friday';
Copy the code
- Arrow function
Arrow function without this, just use it, personally feel looks very clean 0.0
const areFun = (value) =>{
retrun value
};
console.log(areFun(111));
Copy the code
- Template string
The best thing about template strings is that you can add variables to the string, and then make the values assigned to the variables become characters.
const a='xxx',b=11; const c=`${a}-${b}ccccc`; console.log(c); // The output is xxx-11CCCCCCopy the code
- Deconstruction…
Commonly used for array and object assignment;
Const a = [1, 2, 3]; const b = {'x':1,'y':2}; const c = [0,...a]; // const c = [0,1,2,3,4] const {x} = b; // Assign the value of the x attribute in b to the variable x;Copy the code
At present, Promise and async are also very important. This is not used as frequently as the above, but it is also very important. I plan to open a new chapter and talk about it separately.
Finally, an Easter egg…
- eggs
Clever use of Slice!
There are an array,,2,3,4,5,6,7,8,9,10,11,12,13 [1], let you add a 0, in front of less than 10 Numbers into [01,02,03,…, 12, 13] so, what would you do?
Look at the usage of slice.
slice(start,end) ;
Start: required. Specify where to start. If it is negative, it specifies the position from the end of the array. That is, -1 is the last element, -2 is the next-to-last element, and so on.
End: Optional. Specify where to end the selection. This parameter is the array subscript at the end of the array fragment. If this parameter is not specified, the shard array contains all elements from start to the end of the array. If this parameter is negative, it specifies the element from the end of the array.
Ok, start coding:
Let the list =,2,3,4,5,6,7,8,9,10,11,12,13 [1]; list=list.map(ele=>('0' + ele).slice(-2)); Log (list) console.log(list); log(list) console.log(list);Copy the code
The output is:
Solve!
Nice to see the end of it! Code word is not easy, like is the biggest support oh!