const variable definition can not be amended and must be initialized
. 1 const B = 2 ; // correct 2 // const B; // error must be initialized . 3 the console.log ( ' outside the defined function const B: ' + B); // the output value . 4 // B =. 5; . 5 // the console.log ( 'const definitions outside the function modification B:' + B); // can not be output
var variable definitions can be modified, if not initialize prints undefined, not being given
. 1 var A = . 1 ; 2 // var A; // not given . 3 the console.log ( ' outer var function definition A: ' + A); // can be output. 1 = A . 4 function Change () { . 5 A = . 4 ; . 6 the console.log ( ' the function defined var a: ' + a); // can be output. 4 = a . 7 } . 8 Change (); . 9 the console.log ( ' after a function call is defined as a function of the internal var modification value : ' + A); // may output a = 4
let a block-level scope, let the internal function definitions used, no effect on the external function
. 1 let C = . 3 ; 2 the console.log ( ' external function definition let C: ' + C); // output. 3 = C . 3 function Change () { . 4 let C = . 6 ; . 5 the console.log ( ' the function let definition of C: ' + C); // output. 6 c = . 6 } . 7 Change (); . 8 the console.log ( ' defines the internal function is not affected by the definition of the function call let C: ' + C); // output c = 3