javascript-tutorial / javascript-tutorial/en.javascript.info

Suggestion for Additions to Article on Promise

Open
#2,807 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

We can add a section for Promises vs Callbacks to show the inherent advantages of Promise:

Like this :

At the simplest level, Promises are just a different way of working with callbacks. However, there are practical benefits to using them.

  1. One real problem with callback based asynchronous programming is that it is common to end up with callbacks
    inside callbacks inside callbacks
    , with lines of code so highly indented that it is difficult to read.
    Promises allow this kind of nested callback to be re-expressed as a more linear Promise chain that tends to be easier to read and easier to reason about.

  2. Another problem with callbacks is that they can make handling errors difficult. If an asynchronous function (or an asynchronously invoked callback) throws an exception, there is no way for that exception to propagate back to the initiator of the asynchronous operation.
    This is a fundamental fact about asynchronous programming: It breaks exception handling.
    The alternative is to meticulously track and propagate errors with callback arguments and return values, but this is tedious and difficult to get right.
    Promises help here by standardizing a way to handle errors and providing a way for errors to propagate correctly through a chain of promises.

Promises are therefore a powerful idiom for asynchronous programming.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the article on Promises referenced by the issue and review its existing discussion of asynchronous programming. Add a focused “Promises vs Callbacks” section using the supplied points about nesting, readability, and error propagation, then confirm the article reads consistently with the surrounding content.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.