P E N C I L
Login
ES6 let const vs var
  1. http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
  3. var is ES5 
  4. Initializing
    1. var a = 5; let b = 5;
      1. The same: Actually has 2 things:  
        1. When function starts to run, lexical environment is created with a and x (hoisting). Then function code is executing
        2. When executing to the line of declaration, the variable is assigned
      2. The diff: a has value "undefined" when created in lexical environment, b has "reference error" and cannot be used until the assignment b=5
    2. let b   ie.  let b = undefined
      Mean hoist b variable and "when executing the let", assign b=undefined
  5. Block
    1. var: use function block
      var a = 1;  for() { var a =3; }  at the end a =3
      The hoist create only one variable a (ie. a in for is global a of function)
    2. let: variable is scoped to block
      let a = 1; for() { let a = 2; }  at the end a =1
  6. For (let x=1) {}
    The code inner for is executed in a new function with new LexicalEnvironment.
    ie. each loop has differnt reference to i.