async function & no return await All In One
async function & no return await All In One
async function
return await
错误的使用方式 ❌
ESLint no-return-await
/*eslint no-return-await: "error"*/
async function foo() {
// ESLint 检查 ✅
return bar();
}
async function foo() {
// 绕过 ESLint 检查 ❌
await bar();
return;
}
// This is essentially the same as `return await bar();`, but the rule checks only `await` in `return` statements
async function foo() {
// 绕过 ESLint 检查 💩
const x = await bar();
return x;
}
// In this example the `await` is necessary to be able to catch errors thrown from `bar()`
async function foo() {
try {
// 只有需要使用 try...catch 捕捉错误的时候,才需要使用 return await 来获取错误信息 ✅
return await bar();
} catch (error) {}
}
https://eslint.org/docs/latest/rules/no-return-await
no return await
https://javascript.info/async-await
https://zh.javascript.info/async-await
https://github.com/javascript-tutorial/en.javascript.info/tree/master/1-js/11-async/08-async-await
PR
https://github.com/javascript-tutorial/en.javascript.info/pull/3343
https://github.com/xgqfrms/en.javascript.info/tree/patch-1
refs
Learning JavaScript Async Await In Depth All In One / 深入学习 Async Await
https://www.cnblogs.com/xgqfrms/p/17074186.html
https://stackoverflow.com/questions/44806135/why-no-return-await-vs-const-x-await
https://juejin.cn/post/6934300573638328333
https://juejin.cn/post/6891547378231279623
https://github.com/davidlin88/blogs/issues/2
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17074870.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2019-01-30 Python & dict & switch...case All In One
2019-01-30 Spyder & Python All In One
2019-01-30 How to install python3 on macOS All In One
2019-01-30 NLP & AI