ES6面试题总结!

ES6面试题总结!

1.变量

var // 重复声明,函数级
let // 不能重复声明,块级,变量
const // 不能重复声明,块级,常量
2.箭头函数

// a.简写
// ()=>{}
// i. 如果只有一个参数,()可以省略
// ii. 如果只有一个return, {}也可以省略

// b.修正this
3.参数扩展

// 收集参数
function show(a, b, …arge){
alert(a);
alert(b)
alert(arge)
}

// 扩展参数
let arr = [12, 5, 8]
let arr2 = […arr, 9]

// 默认参数
function show2(a, b=5, c){

}
4.数组方法

map() // 映射
reduce() // 汇总
filter() // 过滤
forEach() // 循环
5.字符串

srartWith() // 从什么什么开头
endWith() // 从什么什么结尾
// 字符串模板:
${a}xxx${b}
6.Promise

// 封装异步操作
Promise.all([
$.ajax(), $.ajax()
])
7.generator

function *show3(){
// 暂停函数
yield
}

// 播放
8.JSON

JSON.stringify({ a: 12, b: 5 }) => ‘{ “a”: 12, “b”: 5 }’
JSON.parse(’{ “a”: 12, “b”: 5 }’) => { a: 12, b: 5 }
9.结构赋值

let [a, b, c] = [12, 5, 8];

// 左右结构一样
// 右边是合法的实体
// 声明,赋值一次完成
10.面向对象

// 类
class Test{
constructor(name, pass){
this.name = name
this.pass= pass
}

showName(){
console.log(this.name)
}
showPass(){
console.log(this.pass)
}
}

// 继承
class Cls2 extends Cls1{
constructor(){
super()
}

}
ES7 & ES8

1.数组

// 1. 数组是否包含某个东西
includes()

let arr = [12, 5, 8]
console.log(arr.includes(99)) // false
console.log(arr.includes(8)) // true

// 2. keys/ values/ entries
for…of
for…in // 循环数组循环对象的

let arr = [12, 5, 8, 99, 31]
for(let i in arr){
// 下标
console.log(i)
}

for(let i of arr){
// 值(value)
console.log(i)
}

let json = {a: 12, b: 5, c: 99}
for(let i in json ){
// key
console.log(i)
}

for(let i of json ){
// 报错(不可迭代)
console.log(i)
}

// keys => 所有的key 取出来
// values => 所有的value 取出来
// entries => 所有的key:value 键值对取出来

let arr5 = [12, 5, 8, 99, 660]

for(let key of arr.keys()){
console.log(key)
}
for(let value of arr.values()){
console.log(value)
}
for(let entry of arr.entries()){
console.log(entry)
}
for(let [key, value] of arr.entries()){
console.log(${key}:${value})
}
2.幂

console.log( Math.pow(3, 8) )
console.log( 3**8 )
3.字符串

console.log( ‘abc’.padStart(10, ‘0’) )
console.log( ‘abc’.padEnd(10) )
4.async await

async function show(){
console.log(‘a’)

await;

alert(‘b’)
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值