Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the new ECMAScript6 grammars

Shulou Source: shulou.com Published: 2022-06-01 12:02:58 09月23日 Update

Most people do not understand the knowledge points of this article "what is the new grammar of ECMAScript6?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the new grammar of ECMAScript6?"

First, the premise:

New grammar of ECMAScript6

ECMAScript version of the new syntax, not all browsers are compatible, some browsers are compatible with parts

II. New Grammar of ECMAScript

1. Variable definition

Version 5: var variable name: the scope of use of variables is not clear

For (var I = 0; I

< 10; i++) { console.log("in:"+i) } console.log("out:"+i); 6版本: let const:声明变量 let 变量名 用于声明局部变量 作用范围:从定义行开始到所在代码块结束 for (let i = 0; i < 10; i++) { console.log("in:"+i) } console.log("out:"+i); const修饰的值不可变(相当于java中的final) const修饰的对象地址不可以变,但是属性可以变,可以修改属性 const student={id:1,name:"王恒杰"} console.log(student); //const修饰的对象地址不可以变,但是属性可以变,可以修改属性 student.id=2; console.log(student) //增加属性age student.age=18; console.log(student) 2、箭头函数 使用场景:匿名函数作为函数的参数 语法:()=>

{} is equivalent to function () {} simplifies function

Version 5: function function xx () {}

Version 6: arrow function

/ / Arrow function

Function test (func) {

Func (1)

}

/ / 5 version: function function xx () {}

Test (function (I) {

Alert (I)

})

/ / 6 version: arrow function () = > {function body}

Test ((I) = > {

Alert (I)

})

Note:

(1) when the function has only one parameter, () can be omitted. The parameter is multiple or no argument needs to be added with parentheses.

(2) there is only one line of code in the function body, and {} can also be omitted.

(3) the arrow function does not have its own this. If the this in the arrow function represents the current vue object, it does not represent the current function.

3. Template string--

When defining a variable, you can use the html tag to include it in the variable

/ / template string

Let html= "Click me"

+ "Click me"

+ "Click me"

+ "Click me"

Console.log (html)

/ / template string

Let html1=-- asked me.

Click me.

Click me.

Click me--

Console.log (html1)

4. Create an object

/ / define object

Let id=1

Let name= "Wang Hengjie"

Let age=18

/ / version 5 encapsulates objects

Let student= {id:id,name:name,age:age}

Console.log (student)

/ / version 6 encapsulates objects

Var student2= {id,name,age}

Console.log (student2)

The above is about the content of this article "what are the New Grammar of ECMAScript6"? I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Function version variable syntax object arrow content property parameter character string template code representative only address local article browser knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Shulou Technology Xiaomi Shulou Tech Info