This seems like a simple question, but when you actually answer it, it’s another thing. ES6 is so easy to use that you can’t even remember the arrow function when you really answer the question……
Whether the school recruit or clubs, if you happen to be asked this question, so would you please speak a little more as possible, so that the interviewer will think you are the real master ES6, ES6 content are many, here only lists the commonly used features and their main points, at the time of the interview also need around these points according to own understanding as much as possible. Finally, this article is for interview only, not for ES6. If you want to learn more about ES6, you can read Mr. Ruan’s introduction to ES6
1. The presence of let and const commands
- The difference between let and const :const defines a read-only constant. Once a variable is declared, it must be initialized immediately. It cannot be left for later assignment and cannot be changed.
- There is no variable promotion, declared variables must be used after the declaration, otherwise an error is reported
- It is not allowed to declare a variable repeatedly. It is not allowed to declare the same variable repeatedly within the same scope
- Block-level scope. Before ES6, there were only function scopes and global scopes. A brace is a block-level scope
- The declared variable no longer belongs to window
2. Deconstruct the assignment
- Array, object, string and other basic use of destruct assignment and default value Settings
- The use of deconstruction
(1) values of exchange variables (2) multiple values returned by receiving functions (3) setting of default values of function parameters (4) used for on-demand loading of module imports
3. String extensions
- Template string
- Addition of methods
includes()
.startsWith()
.endsWith()
. - Regular expression for a named group match
4. Numerical extension
- Improved binary (starting with 0b) and octal (starting with 0o) representations
- Method migration and addition 将
parseInt()
andparseFloat()
fromwindow
Object migration toNumber
On the object - The exponent operator **
5. Extension of functions
- Default Settings for function arguments
- Arrow function
Notes on using arrow functions: (1) The this object in the function body is defined, not used. (2) It cannot be used as a constructor, that is, it cannot use the new command, otherwise an error will be thrown. (3) It cannot use the arguments object. If so, you can replace the 3. rest parameter with the REST parameter
6. Array extensions
- Extension operator
Use (1) copy array (2) merge array (3) function rest argument 2. Method extensions array.from (), methods fill(), flat() on instances of array.of ()
7. Extension of objects
- A concise representation of properties and methods
- Attribute name expression
- ergodicity
for.. in
,Object.key(obj)
- Adding the super keyword
- The new method
Object.is()
,Object.assign()
8. Module Imports a Module
At this point, it is important to explain to the interviewer the differences between the ES6 module and the CommoonJS module
- The CommonJS module outputs a copy of the value, and the ES6 module outputs a reference to the value.
- The CommonJS module is a runtime load, and the ES6 module is a compile-time output interface.
You can read this article if you are not sure
9. Other things
- The use and understanding of async and promise are also a common question
- Symbol Data type
- Set and Map structures
- class
Finally, I hope you succeed in the interview. The harder you work, the luckier you will be