Let and const commands in ES6

Source: Internet
Author: User

1.let command

1) Basic usage

The Let command is a new command for declaring a variable, similar to Var, but the ES6 variable is valid only within the code block where the Let command resides.

2) "Declaration in advance" does not exist

Let declaration of the variable does not exist "declaration in advance", the variable must be used after the declaration, otherwise it will cause an error, for example:

Console.log (a); // undefinedconsole.log (b); // Error!  var a=3;let b=3;

3) Temporary Dead Zone

Whenever a let command exists within a block-level scope, the variable it declares binds to the current block-level scope and is unaffected by the external:

1 var tmp=123; 2 3 if (true) {4   tmp= "abc"  ;   Error!  5let  tmp;   6 }

4) Duplicate declarations are not allowed

The Let command does not allow the same variable to be declared repeatedly within the same scope

Let and const commands in ES6

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.