DEV Community

Discussion on: An introduction to promises in JavaScript

Collapse
 
avalander profile image
Avalander • Edited

Nice article, just a small comment.

As long as there is a return statement (either explicit or implicit) in the callback function, both then and catch will return a promise (otherwise they'll return undefined).

In javascript, a function that doesn't return anything technically returns undefined, you can still chain those functions in a promise chain, it's just that the resolved value will be undefined.

fetchSomething()
  .then(data => {
    console.log(data)
    // This function doesn't return anything
  })
  .then(data => {
    // data is undefined, but it's still wrapped inside a promise.
  })
Enter fullscreen mode Exit fullscreen mode
Collapse
 
savagepixie profile image
SavagePixie • Edited

Good catch! I guess I should reword that.
Thanks^