DEV Community

Understanding JavaScript Promises

flavio ⚡️🔥 on February 09, 2018

Introduction to promises A promise is commonly defined as a proxy for a value that will eventually become available. Promises are one w...
Collapse
 
justsml profile image
Daniel Levy

Such a great article. Well written, focused and featuring really solid technique.

Were/Are you an educator? Your examples game is amazing!

The way you chained methods in the fetch example is such a powerful technique.

I've been working on exploring the 'limits' of a similar pattern I call a 'functional river', check it out here: github.com/justsml/escape-from-cal...

:+1: using promises to compose (synchronous and) asynchronous methods in composable chains.

Collapse
 
sunflower profile image
sunflowerseed

I usually don't see the part response.status >= 200 && response.status < 300 and if it is done, won't you need to check for 304 as well?

Usually I see the usage:

  fetch(' url ')
    .then(response => response.json())
    .then(data => { do something with data })
    .catch(err => console.log(err));