Home > Article > Web Front-end > Detailed explanation of scope and declaration of variables in ES6
This time I will bring you a detailed explanation of the scope and declaration of variables in ES6. There are notes on the scope and declaration of variables using ES6. Which ones, the following are practical cases, let’s take a look.
Variable scope and declaration:Compared with es5; the biggest difference is: { }, which is a block scope in the es6 lexical environment; and it is stipulated that variables must first Declare reuse;<!-- 大括号对于 var 方式声明形同虚设--> { var a=1; } <!-- let 只在本大括号中生效;并且一个作用域只能声明一次--> { let aa=1; } console.log(aa) //报错 <!-- const为声明的不能被改变;例如下面的是错误的--> { const a=1; a=2 } //报错I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website
Other related articles!
Related reading:Entry, output, module analysis of webpack3.x
The above is the detailed content of Detailed explanation of scope and declaration of variables in ES6. For more information, please follow other related articles on the PHP Chinese website!