xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

async function & no return await All In One

async function & no return await All In One

async function return await 错误的使用方式 ❌

image

image

image

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, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 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
点击右上角即可分享
微信分享提示