Detailed explanation of let command _javascript skill in ES6

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.