let var const difference

let

  • es6 grammar

  • letScope is block level, i.e., in the range {}

  • If the variable is not declared on the use of the words being given ReferenceError , but varit will error undefined (variable does not exist upgrade)

  • As long as there is scope block-level letcommands, variables declared it would "bind" in this area, no longer subject to external influences. In the code blocks letbefore the command to declare variables, the variables are not available. This is syntactically (temporary dead zone)

    var tmp = 123;
    
    if (true) {
      tmp = 'abc'; // ReferenceError
      let tmp;
    }

where

  • JavaScript standard wording, var scope to only the local and global variables

const

  • const and let the scope of the same, but once assigned a const can not be changed, just the first reference can not be changed, but the value of a variable or can be changed.

Guess you like

Origin www.cnblogs.com/rainymemory/p/10960221.html