Block-level scope: ES6 allow you to use block-level scope, but at the moment most of the ES6 syntax only allowed to use ( "use strict") in strict mode.
1 let keyword
Role: declare a variable, a brace is a scope (each flower in brackets is the new variable).
Features: Not declared upgrade, the role can not access variables outside the block, and as const can only be declared once.
Keyword : Next let, const, function, class ES6 can learn to block scope: https://blog.csdn.net/kittyjie/article/details/50337031
// variable var role in the function declaration outside on a timer for ( var I = 0; I <. 5; I ++ ) { setTimeout(function(){ alert(i); },1000); } // Because let braces as to the scope, for each cycle is going to be re-let to understand let a variable in a for loop: https://zhuanlan.zhihu.com/p/51966830 // let variable role in the brackets, and the outer inaccessible for (the let I = 0; I <. 5; I ++ ) { setTimeout(function(){ alert(i); },1000); }
2 const constant declarations
Role: to define a constant
Features: does not claim to enhance, in blocks, scope, value can not be changed, can only be declared once.
// Set the object is constant, its value can be modified // because we value a constant, but a pointer pointing to the data type of the object stored in the stack memory stack and heap memory: HTTPS: //www.cnblogs. COM / liveoutfun / P / 8962019.html const {A obj =:. 1, B: 2, C:. 3 } obj.a = 100; console.log(obj.a); //10
3 arrow function
Role: The simple format of a function declaration
Features: compact than conventional format function (not a function, return, a single parameter parenthesis), and this point is a pointer to a function of the higher
// Normal function declaration format var A = function () { return . 1. 1 + ; } // arrow function declaration format var A = X => { . 1. 1 + ; } // plurality of parameters var A = (X, Y, Z) => { . 1. 1 + ; }
4 Destructuring deconstruction
Role: The value can be by way of deconstructing
// general definition of the variable wording var X = 10, Y = 20 is, Z = 30 ; // destructuring assignment to a plurality of variable assignment allows you the let [X, Y, Z] = [10,20,30 ]; let [x,[a,b],y] = [10,[15,18],20]; This is not defined in the array, but by matching structures on both sides of the equal sign, assignment. // destructuring assignment allows you to take a value of at least: the let [X, Y] = [10,20,30]; // results 10 = X, Y = 20 is the let [X, [A, B], Y] = [ 10, [5], 20]; // result x = 10, a = 5, y = 20, b = undefined browser does not complain, still assignment is successful. // can use the object values of the order
var {ID, name, Age} = {name: 'YT', Age: 30, ID = 30}
// Use // can easily swap the values of two variables [A, B] = [B, A];
// may be a value of a plurality of variables [A, B] = () => { return [. 1 2 ]}
// target values format may not consider the order of {a, B, C} = {B:. 1, a: 2, C:. 3 }
// array or from a particular object var {a: NewName obj =}; // objects var [0: the NewName] = ARR; // array
Summary: The value of an array can batch format, the format of the object can disrupt the order value
Some methods of the string 5
Role: ECMA6 strings can be faster string concatenation
// fast string concatenation var str = `I ECMA $ {variable} string expression` // string wrap no error var STR = ` No error !! '
Some methods 6 array
Array.from (Pseudo array) // dummy array may be converted to an array
Array.copyWithin (subscript element is replaced, the cutout start index, end taken subscript); // copy element replacement element (train service)
Array.find (function (value, index, arr) {return value> 10}) // filtration and the like, only to find one of the elements that match the conditions.
Subscript findIndex (function (value, index, arr) {}) // find and the like, but a return is in line with the requirements of the elements
7 Object.assign
8 The seventh data types Symbol
9 Set and Map collections
10 Map collection that is mapped