Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript How to Make a Promise?

Jared Hensley
Jared Hensley
8,106 Points

Is the .then() considered the "resolver"?

Is the .then() considered the "resolver". I work with promises a good bit, but often just follow my muscle memory. Being able to elegantly explain the promise API in an interview would be excellent!

1 Answer

Tim Smith
Tim Smith
6,069 Points

I think you might be mixing up the semantics of "resolve". In the context of the way Andrew explains it, when a promise is "resolved/fulfilled", he's implying that the original function has yielded a proper value and not caused an error. This makes sense when you consider that then() can take an optional second argument, a function to be called if the promise fails in some way. We can also add the catch() method to the end of a chain of then() calls and catch() will display an error if any promise in the chain fails (which is helpful for staying DRY).

tl;dr: then() is the resolver when all goes well or it takes the optional second argument to handle all possible cases (the promise worked or not), otherwise it needs a call to catch() to exhaust all possible outcomes of the promise call.

Alexander Køpke
Alexander Køpke
5,065 Points

Very well written answer that, in my opinion, clears up any misunderstanding that might occur.