async 和 await

async和await的使用html

async

async 异步执行

用法:异步

async function name () {
    return 'hello'
}

console.log(name())

console.log('world')

async 后面的函数的执行不会阻碍后面console的执行,两个语句是同时执行的。async

await

await 同步执行

用法:函数

await function name () {
    return 'hello'
}

console.log(name())

console.log('world')

await 后面的函数执行完了才能执行后面的语句。code

相关文章
相关标签/搜索