js的async和await
时间: 2023-08-30 08:08:47 浏览: 113
async和await是JavaScript中处理异步编程的一种新方式。它们可以让异步操作的结果像同步操作一样被处理,从而使得异步编程更加简洁和易读。async函数的返回值是一个Promise对象。await关键字只能在async函数中使用。它用于等待返回Promise对象的异步函数执行完成。在使用await时,JavaScript引擎会暂停执行当前函数,直到异步操作完成。需要注意的是,await关键字只能在async函数中使用,否则会导致语法错误。如果在非async函数中使用await关键字,会导致语法错误。同样需要注意的是,如果await的Promise失败了,就会抛出异常,需要通过try...catch捕获处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [JS异步函数async和await](https://blog.csdn.net/qq_45707021/article/details/131457101)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [js中async与await详解](https://blog.csdn.net/weixin_45629285/article/details/130925510)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文