JS declare variables
Js way to declare variables There are three: let, const, var
1.const If the definition of simple data types, becomes constant, variable values can not be changed.
const name="lili"; name="lucy"; console.log(name);//error
2.Var can repeat declare a variable, and covers the value of the variable, and variables defined wherever, are global variables. If the second var statement but did not assign the same variable, the variable is assigned a value, or a statement of the first value.
was test = 3 ; was the test; console.log (test); // 3
was test = 3 ; was test = 5 ; console.log (test); // 5
3.Let not repeat the statement, repeated error statement. Locally declared as local variables defined in the global, compared with global variables. Define local repeated, preferentially used locally defined variables.
let a=10; { let a=12; console.log(a);//a=12 } console.log(a);//a=10