let,const

- Let webstorm supports syntax ES6: the right of file-setting-languages ​​& frameworks-javascript- select ES6
- let pre-defined variables are not explained and can not be redefined before the variable definitions given output. var explained with a pre-defined variables, output variables are defined prior to undefined
- not only in the {ES6} function it is called private scope, all {} are called private scope. For example, if (condition) {} is determined, for (var i = 0; i <10; i ++) {}
  - ES6 as long as the {} are private block-level scope, the role of the block-level and block level outside scope, defined a variable not conflict. Because it is not a space
for (var i = 0; i <oLis.length; i ++) { 
Olis [i] .onclick = function () {
Alert (i);
}
}
// Bind event is asynchronous, when we click on an element triggers when you bind him event loop had executed i i value is already completed the cycle does not meet the conditions, in which case no matter which element click on the pop-up index is an index does not meet the conditions for cycling

To let the click var element can be indexed correctly, because each execution loop formed proprietary block-level scope save the correct index is not changed outside variables 
for (let i = 0; i <oLis.length ; I ++) {
    Olis [I] .onclick = function () {
        Alert (I);
    }
}
- const defined is constant, and no explanation and not repeated pre-defined.
  - the entire value can not be changed (if it is an array or an object which may change, but if the referenced address is changed will be given coverage)
the let, const, if the statement of the same function is repeated a variable declaration, an effect


 

Guess you like

Origin www.cnblogs.com/zlsqd/p/11332562.html