当前位置:网站首页>ECMAScript 6(es6)
ECMAScript 6(es6)
2022-06-27 10:54:00 【Dalei programmer (light and large)】
1、ECMAScript 6
1.1 What is? ECMAScript 6
ECMAScript 6.0( abbreviation ES6) yes JAvascript The next generation standard of language . Its goal , Is making Javascript Language can be used to write complex large applications , Become an enterprise development language .
1.2 ECMAScript 6 and JAvascript The relationship between
ECMAScript 6 and JAvascript The relationship is , The former is the latter's specification , The latter is an implementation of the former ( additional ECMAScript Dialects and Jscript and ActionScript)
2、 Basic grammar
2.1 let Declare variables
//var Declared variables have no local scope
//let Declared variable has local scope , Can only be used in the corresponding code block
{
// Defining variables
var a=0
let b=2
}
console.log(a)//0
console.log(b)//b is not defined
//var Declared variables can be assigned multiple times
//let A declared variable can only be assigned once
var m=1;
var m=2;
let n=10;
let n=20;
console.log(m) //2
console.log(n)//Identifier 'n' has already been declared
2.2 const declare constant
stay es6 Constants declared in must be assigned values , And it can't be assigned again .
const a=0;
a=4;//Assignment to constant variable.
const b;//Missing initializer in const declaration
2.3 Deconstruct assignment
Deconstructing assignment is an extension of assignment operator . It is a pattern matching method for arrays or objects , And then assign values to the variables .
Concise and readable in code writing , The meaning is clearer ; It is also convenient to obtain data fields in complex objects
An array of deconstruction
Tradition :
let a=1,b=2,c=3;
console.log(a,b,c)
ES6:
let[x,y,z]=[1,2,3]
console.log(x,y,z)

Object to deconstruct
Tradition :
let user={name:'Helen',age:18}
let name1=user.name
let age1=user.age
console.log(name1,age1)
ES6:
let{name,age}=user // Be careful : The variable of the structure must be user Properties in
cosnole.log(name,age)

2.4 Template string
Templates
The string is equivalent to the enhanced string , Use back quotes `, Except as a normal string , It can also be used to define multiline strings , You can also add variables and expressions to a string
Insert variables and expressions into the string . The variable name is written in ${} in ,${} You can put JavaScript expression .
let name="lucy"
let age=20
let info=`My name is ${name} ,
I am ${age+1}`
console.log(info)
2.5 Declaration object abbreviation
// Traditionally defined objects
const name="lucy"
const age=18
const user1={name:name,age:age}
console.log(user1)
//es6
const user2={name,age}
console.log(user2)

2.6 Object extension operators
Extension operator (...) Used to extract all traversable properties of the parameter object and copy it to the current object
//1、 Copy the object
let person1={name:"Amy",age:18}
let someone={...person1}
console.log(someone)
//2、 Merge objects
let age={age:18}
let name={name:"Amy"}
let person2={...age,...name}
console.log(person2)

2.7 Arrow function
Arrow functions are often used to define anonymous functions
// Tradition
var f1=function(a){
return a
}
console.log(f1(1))
//ES6 Use the arrow function to define
// Parameters => The body of the function
var f2=a=>a
console.log(f2(1))
var f3=function(m,n){
return m+n
}
console.log(f3(1,2))
var f4=(m,n)=>m+n
console.log(f4(1,2))

边栏推荐
- Leetcode 729. 我的日程安排表 I(牛逼,已解决)
- Technology is as important as business. It is wrong to favor either side
- 【TcaplusDB知识库】TcaplusDB集群管理介绍
- 闭包的常见问题
- Glide缓存机制
- Ubuntu手动安装MySQL
- torch. utils. data. Randomsampler and torch utils. data. Differences between sequentialsampler
- go-zero微服务实战系列(七、请求量这么高该如何优化)
- If you find any loopholes later, don't tell China!
- 红包雨: Redis 和 Lua 的奇妙邂逅
猜你喜欢

微软云 (Microsoft Cloud) 技术概述

oracle触发器 存储过程同时写入

Write it down once Net analysis of a property management background service stuck

Error im002 when Oracle connects to MySQL

Learning notes - data set generation

NVME2.0协议——新特性

Easy to understand Laplace smoothing of naive Bayesian classification
![[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction](/img/85/39e54ebc613f6d1dc7f02168adaaee.png)
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction

Native JS implements page scroll bar loading data and page drop-down loading content

mysql数据库汉字模糊查询出现异常
随机推荐
基于swiftadmin极速后台开发框架,我制作了菜鸟教程[专业版]
istio相关资料
leetcode:522. Longest special sequence II [greed + subsequence judgment]
直播電子商務應用程序開發需要什麼基本功能?未來發展前景如何?
Design and Simulation of direct torque control system for induction motor (motion control matlab/simulink)
. Net
Uniform Asymptotics by Alexei
[tcapulusdb knowledge base] tcapulusdb cluster management introduction
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
2-4 installation of Nessus under Kali
Change PIP mirror source
[methodot topic] what kind of low code platform is more suitable for developers?
Brother sucks 590000 fans with his unique "quantum speed reading" skill: look at the street view for 0.1 seconds, and "snap" can be accurately found on the world map
直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?
Learning notes - data set generation
记一次 .NET 某物管后台服务 卡死分析
Basic violin plot in R with plot
Future & CompletionService
Queue, two-way queue, and its application
居家办公竟比去公司上班还累? | 社区征文