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

JavaScript promise parameters

Hello,

I do not understand why we pass arguments into the parameters of the anonymous function function(response, reject) and how we can use them to do something. So what is their meaning and what values do we pass in to replace them?

var example = new Promise(function(response, reject){
    resolve("Hello world");
});

Thanks!

1 Answer

Steven Parker
Steven Parker
243,215 Points

The parameters in the promise callback stand for other callback functions. One of them gets called when the promise has been either resolved or rejected, as their names imply.

Have you seen the workshop on Understanding Promises in JavaScript?