Es6 entry, es6

Source: Internet
Author: User

Es6 entry, es6

Now let's take a look at es6, which is now a popular language, but not all browsers are compatible with all the features described by E6,

But we should still learn ES6 syntax.

Because of compatibility, we have to learn about Babel. It is a widely used ES6 converter that can convert ES6 code into ES5 code and execute it in an existing environment.

Variable declaration:

Let, const

The scope of let is a code block. It does not allow the first bullet and then the definition will report an error.

  

{Let a = 12; alert (a) // let is a code block a = 12} alert (); // because let's scope is code block a = undefined alert (a); // undefined var a = 12; alert (); // If let is not allowed to play first and then define it, the error "let a = 12" will be reported.

 

If you do not allow repeated declaration of variables, an error is returned.

Const declares a constant. Once assigned, it cannot be modified. Like let, there is no pre-resolution function, and an error is reported.

The variable declared by const must have a value and an initial value. Otherwise, an error is reported.

    {            const a=12;            console.log(a)        }        alert(a)

 

The initial value must be given. Otherwise, an error will be reported.

For of can loop the array, but there will be problems, and the json loop cannot

Name indicates a group of keys and values that are followed by an array.
There is also a new data type: Symbol ()
Function Arrow:
    
Window. onload = () => {var oDiv = document. getElementById ("div"); // oDiv. onclick = () => {// alert (this); // In the arrow function, this points to window // oDiv. style. background = "red"; //} let show = () => {oDiv. style. background = "blue";} oDiv. onclick = show; let move = (obj = "obj must be passed", {}={}, options) =>{ console. log (obj) ;}; move (1 );}

 

Finally, deconstruct assignment:
// Mode matching & deconstruct value json is the same as var {a = 12, B, c }={ B: 1, c: 2}; console. log (a, B, c)
 

 



  

  

  

Related Article

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.