Home  >  Article  >  Web Front-end  >  Detailed explanation of scope and declaration of variables in ES6

Detailed explanation of scope and declaration of variables in ES6

php中世界最好的语言
php中世界最好的语言Original
2018-03-10 14:12:231735browse

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

##Vue2 tab switching method


Detailed explanation of Vue’s 2.0 component registration

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!

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