Home > Web Front-end > JS Tutorial > body text

Does `return await` Impact Performance Significantly?

DDD
Release: 2024-11-18 09:59:02
Original
614 people have browsed it

Does `return await` Impact Performance Significantly?

Does return await Impact Performance?

Despite the eslint rule "no-return-await" suggesting that it introduces performance issues, this isn't entirely true.

The MDN documentation showcases an example of return await without highlighting any potential performance concerns.

Impact on Performance:

In reality, return await does not lead to a significant performance problem. It simply adds an unnecessary operation, making the execution slightly longer. It's comparable to the innocuous return x 0 for an integer x.

Why It's Considered Poor Practice:

Although return await doesn't harm performance, it's regarded as poor style. It indicates a lack of understanding of promises and async/await.

One Exception:

In the following scenario, return await makes a crucial difference:

try {
    …
    return await …;
} …
Copy after login

await catches rejections and ensures the promise resolution before executing catch or finally handlers. A plain return would have ignored this behavior.

The above is the detailed content of Does `return await` Impact Performance Significantly?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template