Summary of 22 ES6 knowledge points, bursting liver

1. Q: What is ES6, why should we learn it, and what will happen if we don’t learn ES6?

Answer: ES6 is a new generation of JS language standards. It has upgraded and optimized the core content of the JS language, standardized the use of JS, and added JS native methods, making the use of JS more standardized, more elegant, and more suitable for the development of large-scale applications. . Learning ES6 is the only way to become a professional front-end regular. You can write code to fight devils without learning ES6, but you can only be a guerrilla captain at most.

2. Q: What is the difference between ES5, ES6 and ES2015?

A: ES2015 specifically refers to the new generation of JS language standards released in 2015, and ES6 generally refers to the next generation of JS language standards, including ES2015, ES2016, ES2017, ES2018, etc. At this stage, in most scenarios, ES2015 is equivalent to ES6 by default. ES5 generally refers to the previous generation of language standards. ES2015 can be understood as the time boundary between ES5 and ES6.

3. Q: What is babel and what does it do?

A: babel is an ES6 transcoder that can convert ES6 code to ES5 code for compatibility with platforms that do not yet support ES6.

4. Q: What is the use of let, and why should let be used when var is present?

Answer: Before ES6, you can only use var to declare variables. It is actually very unreasonable to declare variables in var. To be precise, it is very unreasonable because there is no block-level scope in ES5. It can even be said that it is a language level. (This is also one of the disadvantages of many C++ and Java developers who can’t understand and look down on JS language). Without block-level scoping, there will be a lot of incomprehensible problems, such as for loop var variable leakage, variable overwriting, etc. Variables declared by let have their own block-level scope , and the variable hoisting problem caused by var-declared variables has been fixed.

5. Question: What are some common upgrade optimizations ES6 does to String type?

answer:

1. Optimization part:

ES6 has added a new string template. When splicing large strings, the backslash (`) is used to replace the previous form of string addition, which can retain all spaces and newlines, making the string splicing look more intuitive and more grace.

2. Upgrade part:

ES6 adds the includes() method to the String prototype, which is used to replace the traditional method that can only use indexOf to find contained characters (indexOf returns -1 to indicate that it is not as clear as the includes method to return false, and the semantics are clearer), in addition Also new methods such as startsWith(), endsWith(), padStart(), padEnd(), repeat() have been added, which can be easily used to find and complete strings.

6. Question: Give some common upgrade optimizations for Array array types in ES6?

answer:

1. Optimization part:

a. Array destructuring assignment. ES6 can directly start with let [a,b,c] = [1,2,3]

The post , a summary of 22 ES6 knowledge points, first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9336
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment