es6 / 7/8 Simple Explanation

1. The change of variables, adds the concept of block-level scope

  • let declare variables (block-level scope), let a more perfect var, global variable that is not declared global properties widow of variables, which will solve the problem for loop variable coverage

    const Constant declaration (block count scope)

  • Var // 
    var a = []; 
    for (var index = 0; index < 10 ; index ++) { 
    
      a [index] = function () { 
          the console.log (index); // index looks up to a scope index value 
      } 
    
    } 
    the console.log (index); // 10 
    A [. 6] (); // 10 
    
    // the let 
    const A = [];
     for (the let index = 0; index <10; index ++) { 
      A [index] function = () {the console.log (index);} // index is effective only in the current round of cycles, each cycle will create a new variable 
    } 
    a [. 6] (); //. 6 
    the console.log (index); / / index not defined

     

2. Add the string method

STR = the let 'Happy'; 
the console.log (str.includes ( 'HA')) to true // 
the console.log (str.repeat (. 3)) // 'happyhappyhappy' 
the console.log (str.startsWith ( 'HA' )); // true, to find a position parameter 2 
console.log (str.endsWith ( 'p', 4)); // true, the parameter string length 2 to look

 

 

 

Guess you like

Origin www.cnblogs.com/huangjian8280/p/12598542.html