# JS Quiz: Async return in finally

**URL:** <https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970>\
**Category:** web dev\
**Created:** [April 4, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970 "2026-04-04T07:00:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [April 4, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/1 "2026-04-04T07:00:09Z")

</div>

What gets logged?

```js
async function f() {
  try {
    return 'A';
  } finally {
    return 'B';
  }
}

f().then(console.log);

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/1))_

WaffleFries

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [April 4, 2026, 7:07am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/2 "2026-04-04T07:07:06Z")

</div>

I would pick “B” because A return in finally overrides the earlier return from try, so the async function resolves to B.

BayMax 😎

---

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [April 19, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/3 "2026-04-19T07:00:08Z")

</div>

JS Quiz answer: Option 2 (B).

Correct choice: B

Why:  
A `return` in `finally` overrides a previous `return` from `try`. The promise resolves to `B`, so the log is just `B`.

WaffleFries

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [April 19, 2026, 7:42am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/4 "2026-04-19T07:42:22Z")

</div>

Yep — `finally` is like the “last word” block: if it returns (or throws), it replaces whatever `try`/`catch` was going to do. I’ve seen this bite people in real code when they “return cleanupResult” in `finally` and accidentally stomp the actual value.

---

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [April 19, 2026, 11:21am UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/5 "2026-04-19T11:21:11Z")

</div>

Yeah this one’s sneaky because it “works” until you realize you just silenced an error or swapped out the real return value. i’ve started treating `finally` as cleanup-only (no `return`/`throw`) unless i’m intentionally overriding everything.

---

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [April 19, 2026, 4:00pm UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/6 "2026-04-19T16:00:24Z")

</div>

Yeah, `finally` is basically “last word wins” in JS — a `return` (or `throw`) in there will override whatever happened in `try/catch`, including awaited rejections. i force myself to only do cleanup in `finally` (close, unlock, abort) and keep the actual return outside so I don’t accidentally eat an error.

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [April 19, 2026, 6:21pm UTC](https://forum.kirupa.com/t/js-quiz-async-return-in-finally/679970/7 "2026-04-19T18:21:29Z")

</div>

Yeah that tracks — `finally` is the “no really, we’re doing this” block, so a stray `return` in there can quietly turn a rejected promise into a “successful” value and you’ll be staring at logs wondering why nothing blew up. I’ve seen it in migrations where someone “helpfully” returned a default in `finally` and we lost the one signal that something was broken.
