前端ES6

(1) let和const

let 声明一个变量
const 声明一个常量

(2) 字符串扩展

includes(param):返回布尔值,表示是否找到了param参数字符串
startsWith(param):返回布尔值,表示param参数字符串是否在原字符串头部
includes(param):返回布尔值,表示param参数字符串是否在原字符串尾部

(3) 数组解构

let arr = [1, 2, 3]
const [a, b, c] = arr
console.log(a) // a= 1
console.log(b) // a= 2
console.log(c) // a= 3

(4) 对象解构

const person = {
	name:'xu',
	age:20,
}
const { name:newName, age:newAge } = person
console.log(newName) // newName= xu
console.log(newAge ) // newAge = 20

(5) 函数参数默认值

function add(a, b=1){
	return a+b;
}

(6) 箭头函数

function show(a){
	console.log(a);
}
==>
const show2 = a => console.log(a);
------------------------------------------------
function add(a,b){
	console.log(a+b);
}
==>
const add2 = (a,b) => console.log(a+b);
------------------------------------------------
function add(a,b){
	let c = a + b
	return c;
}
==>
const add2 = (a,b) =>{
	let c = a+b;
	return c;
}

(7) 箭头函数结合解构表达式

const person = {
	name:'xu',
	age:20,
}
const hello2 = ( {name} ) => console.log(name);

(8) map函数

let arr = [1, 2, 3]
let newArr = arr.map(item => return item+1);
// 返回 [2, 3, 4]

(9) reduce函数

let arr = [1, 2, 3]
let newArr = arr.reduce((a,b)=>return a+b);
// 返回6

(10) 扩展运算符

console.log(...[1, 2, 3]) // 1,2,3

//数组合并
let arr = [...[1, 2, 3],...[4,5,6]]
console.log(arr) // 1,2,3,4,5,6

//与解构表达式结合
const [first, ...rest] = [1,2,3]
console.log(rest) // 2,3

(11) 异步函数Promise

const p = new Promise((resolve, reject)=>{
	setTimeout(()=>{
		let num = Math.random();
		if(num<0.5){
			resolve('success' + num);
		} else{
			reject('error' + num);
		}
	});
});

p.then(value=>{
	console.log(value);
}).catch(error=>{
	console.log(error);
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值