Es6 entry, es6
Now let's take a look at es6, which is now a popular language, but not all browsers are compatible with all the features described by E6,
But we should still learn ES6 syntax.
Because of compatibility, we have to learn about Babel. It is a widely used ES6 converter that can convert ES6 code into ES5 code and execute it in an existing environment.
Variable declaration:
Let, const
The scope of let is a code block. It does not allow the first bullet and then the definition will report an error.
{Let a = 12; alert (a) // let is a code block a = 12} alert (); // because let's scope is code block a = undefined alert (a); // undefined var a = 12; alert (); // If let is not allowed to play first and then define it, the error "let a = 12" will be reported.
If you do not allow repeated declaration of variables, an error is returned.
Const declares a constant. Once assigned, it cannot be modified. Like let, there is no pre-resolution function, and an error is reported.
The variable declared by const must have a value and an initial value. Otherwise, an error is reported.
{ const a=12; console.log(a) } alert(a)
The initial value must be given. Otherwise, an error will be reported.
For of can loop the array, but there will be problems, and the json loop cannot
Name indicates a group of keys and values that are followed by an array.
There is also a new data type: Symbol ()
Function Arrow:
Window. onload = () => {var oDiv = document. getElementById ("div"); // oDiv. onclick = () => {// alert (this); // In the arrow function, this points to window // oDiv. style. background = "red"; //} let show = () => {oDiv. style. background = "blue";} oDiv. onclick = show; let move = (obj = "obj must be passed", {}={}, options) =>{ console. log (obj) ;}; move (1 );}
Finally, deconstruct assignment:
// Mode matching & deconstruct value json is the same as var {a = 12, B, c }={ B: 1, c: 2}; console. log (a, B, c)