网站百度抓取/cilimao磁力猫最新版地址
includes
判断是否存在数组中,存在就返回true
const NBA = ['james','kobe','curry']
console.log(NBA.includes('james')) //true
**
例如2的10次方
console.log(2 ** 10) 1024
async
async函数的返回值为promise对象
promise对象的结果由async函数执行的返回值决定
举例
async function fn(){//返回一个字符串// return 'lsh'//返回的结果不是一个promise类型的对象,返回的是一个成功的promise//抛出错误,返回的是一个失败的promise// throw new Error('出错啦')//返回的结果如果是一个promise对象return new Promise((resolve,reject)=>{// resolve('成功的数据')reject('失败的数据')})
}const result = fn()
console.log(result)result.then((res)=>{//console.log(res)
}).catch((err)=>{console.log(err)
})
await
await必须写在async函数中
await右侧的表达式一般为promise对象
await返回的是promise成功的值
await的promose失败了,就会抛出异常,需要通过try...catch捕获处理
结合使用
const p = new Promise((resolve,reject)=>{// resolve('成功的值')reject('失败的值')
})async function main(){try{let result = await p;console.log(result)} catch(e){console.log(e)}
}
main()
entries,getOwnPropertyDescriptors
声明对象
const school = {name:'lsh',age:'18',cities:['北京','上海']
}
entries返回一个数组
const m = new Map(Object.entries(school))
console.log(m.get('cities'))
对象属性的描述对象,可以用于深拷贝
console.log(Object.getOwnPropertyDescriptors(school))