content icon indicating copy to clipboard operation
content copied to clipboard

Wrong Promise.prototype.finally() description

Open HelpMe-Pls opened this issue 4 years ago • 9 comments

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

What specific section or headline is this issue about?

Description

What information was incorrect, unhelpful, or incomplete?

There are 2 paragraphs in the Description where I found to be misleading due to the fact that I tried to execute those expressions and the output is not as mentioned: image

What did you expect to see?

  • When I executed Promise.reject(3).then(() => {}, () => 88), it returns a fulfilled promise with the value 88 (not "return a rejected promise with the reason 88" as mentioned in the section): image

Which matches the return value of the Promise.prototype.then() method: image

  • The Promise.reject(3).finally(() => throw 99) actually throws an uncaught exception: image

Which I believe just a typo. Can be fixed by adding a pair of curly braces: Promise.reject(3).finally(() => {throw 99});

  • The execution of Promise.reject(3).finally(() => Promise.reject(99)) actually returns a rejected promise with the reason 99: image

Which abides by the return value of the Promise.prototype.finally() method: image

  • Assuming the typo from Promise.reject(3).finally(() => throw 99) is fixed (because if it were intended to be syntactically wrong, the author should've mentioned that), the phrasing with "either...or" isn't the right choice of words, because they BOTH will return a promise that is rejected and has a value of 99.

Do you have any supporting links, references, or citations?

Already listed above.

Do you have anything more you want to share?

I'm still learning Promise and its related topics so I'm unable to formulate a definitive example for that case. I'd like the reviewers to have their insights on this and maybe come up with a better code sample to ease in the reading process.

MDN metadata

Page report details
  • Folder: en-us/web/javascript/reference/global_objects/promise/finally
  • MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
  • GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/global_objects/promise/finally/index.md
  • Last commit: https://github.com/mdn/content/commit/4e4ec5dbe15ae4883201057aaab8833dd33b7a05
  • Document last modified: 2022-06-30T11:02:34.000Z

HelpMe-Pls avatar Jul 07 '22 16:07 HelpMe-Pls

Can I work on this?

hiteshvijayhv avatar Jul 08 '22 00:07 hiteshvijayhv

@hiteshvijayhv Yes please :ok_hand: If you have any practical examples to signify the use cases of this particular event: image

Then your contribution is definitely most welcomed :sparkles:

HelpMe-Pls avatar Jul 08 '22 03:07 HelpMe-Pls

Yes, the first one is definitely wrong—the onRejected handler returning normally would still cause the promise to fulfill.

Josh-Cena avatar Jul 08 '22 03:07 Josh-Cena

@Josh-Cena Most definitely. As a learner, I found those statements very confusing.

HelpMe-Pls avatar Jul 08 '22 03:07 HelpMe-Pls

@hiteshvijayhv Yes please 👌 If you have any practical examples to signify the use cases of this particular event: image

Then your contribution is definitely most welcomed ✨

From what I found is that finally() is used to place the code that is executed after the Promise is executed and we want to free up the resources. And this is what that is mentioned there in the docs.

I think this issue is for correcting the doc error instead of addition of more examples.

I will open a new issue regarding the practical implementation of finally()

hiteshvijayhv avatar Jul 08 '22 03:07 hiteshvijayhv

@hiteshvijayhv Sure. Let's make the document better for the fellow learners.

HelpMe-Pls avatar Jul 08 '22 04:07 HelpMe-Pls

I will make a new PR with all fix sorry for messing up

hiteshvijayhv avatar Jul 08 '22 04:07 hiteshvijayhv

No worries. Keep up the good work 💯

HelpMe-Pls avatar Jul 08 '22 04:07 HelpMe-Pls

No worries. Keep up the good work 💯

Thanks a lot.

hiteshvijayhv avatar Jul 08 '22 05:07 hiteshvijayhv