There are three ways to declare variables in javascript: VAR, let, and Const. The following is a description of JS in three ways to define the variable const, VAR, let the difference.
variables defined by 1.const cannot be modified and must be initialized .
Const B = 2; // correct // Console.log (' Outside the function const definition B: ' + B '); // with output value // B = 5; // Console.log (' Outside of the function ' modifies the const definition B: ' + B ');//Cannot output
2.var defined variables can be modified, if not initialized will output undefined, will not error.
var a = 1; // var a;//does not error Console.log (' Out of function var definition a: ' + a '); // can output a=1 function = 4; Console.log (' var within the function defines a: ' + a '); // can output a=4 } change (); Console.log (' function call after Var definition A is the function's internal modified value: ' + a '); // can output a=4
3.let is a block-level scope, and after the function is defined with let, there is no effect on the outside of the function.
Let C = 3; Console.log (' Out of function let definition C: ' + C '); // Output c=3 function = 6; Console.log (' within function let definition C: ' + C '); // Output c=6 } change (); Console.log (' a let definition after a function call is not affected by the internal definition of the function: ' + C '); // Output c=3
Transferred from: http://www.jb51.net/article/94495.htm
Analysis of the difference between Const, VAR and let in JavaScript