Home  >  Article  >  Web Front-end  >  JavaScript es6 entry-level knowledge explanation

JavaScript es6 entry-level knowledge explanation

巴扎黑
巴扎黑Original
2017-07-22 17:51:181729browse

Now let’s learn es6. It is a popular language now, but not all browsers are compatible with all the features of E6.

But we should still learn the syntax of ES6.

Because of compatibility, we have to learn about Babel, which is a widely used ES6 converter that can convert ES6 code into ES5 code so that it can be executed in the existing environment.

Variable declaration:

let, const

The scope of let is a code block. It does not allow to be bombed and then defined, and an error will be reported

#
{
    let a=12;
    alert(a) //let的作用域是代码块  a=12}
    alert(a); //因为let的作用域是代码块 a=undefinedalert(a);  //undefinedvar a=12;

        alert(a);//let不允许先弹再定义  会报错let a=12

It is not allowed to declare variables repeatedly and an error will be reported

The const declaration is a constant, which is not allowed to be modified once assigned. It is the same as let, no The pre-parsing function will report an error

The variable declared by const must have a value and an initial value must be given, otherwise an error will be reported

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

<span style="font-size: 16px">  必须给初始值,不然会报错<br><br>  for of可以循环数组,但是会出问题,循环不了json<br><br>  name指的是一组  键和值  出来之后是数组<br>  还有一种新的数据类型:</span><span style="font-size: 16px">Symbol()<br>  函数箭头:<br>    </span>
  window.onload=()=>{var oDiv=document.getElementById("div");//                oDiv.onclick=()=>{//                    alert(this);//箭头函数中this指向是window//                    oDiv.style.background="red";//                }let show=()=>{
                oDiv.style.background="blue";
            }
            oDiv.onclick=show;
            let move=(obj="obj必须传递",{}={},options)=>{
                console.log(obj);
            };
            move(1);
        }

<span style="font-size: 16px">最后解构赋值:<br></span>
//模式匹配&解构赋值  json 同理var {a=12,b,c}={b:1,c:2};
        console.log(a,b,c)
<br>

<br><br>

 

 

 

The above is the detailed content of JavaScript es6 entry-level knowledge explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn