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

相關文章
相關標籤/搜索