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
{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!