Let is the new copy command inside the ES6, let assignment commands can only be invoked in the {} code block. Here is an example to explain the Let command in Es6, the details are as follows:
The use of the 1.let command is similar to the Var command, but the variable declared by the Let command is valid only within the code block of Let
{Let
a=10;
var b=1;
}
Console.log (a);//uncaught referenceerror:a is not defined
Console.log (b);
The 2.let command does not save the "declaration ahead" phenomenon, so the variables must be declared before using the
Console.log (foo);
Console.log (bar);
var foo=2;//undefined let
bar=3;//uncaught referenceerror:bar isn't defined
3. As long as a let command exists within the current block-level scope, the variable it declares binds to the block-level scope and is no longer affected by the external
var tmp=123;
if (true) {
tmp= ' abc ';//uncaught referenceerror:tmp is not defined because the same variable exists in the block-level scope with the LET command declaration, violating the use principle Let
tmp;
}
The 4.let command does not allow repeated declarations of the same variable within the same scope
function foo () {let
a=10;
Let A=1;//uncaught syntaxerror:identifier ' a ' has already been declared
}
The above is a small set to introduce the ES6 in the Let order, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!