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 Asynchronous Programming with JavaScript Understanding Promises Perform Cleanup With finally()

How promises perform asynchronous tasks?

I understand how callback works asynchronously, but I cannot understand how promise does it.

Reggie Williams
Reggie Williams
Treehouse Teacher

Hey jun cheng wong promises work like callbacks and differ in syntax. Which part of promises were you unsure about?

Hi, can you provide me an example of how promises not blocking the other code to run?

1 Answer

If you understand how callback works asynchronously, then you can see when declaring a new Promise, it accepts a parameter which is a callback function. Promise uses a callback function, and callback function works asynchronously, therefore Promise works asynchronously.

The callback function is the one that is passed two arguments (resolve and reject).

This is my understanding so someone feel free to correct me if I'm wrong.

EDIT: I am not sure whether or not callback functions by themselves are asynchronous (probably not?), but they are often seen in asynchronous operations due to the ordering in which it's executed. Also now I'm second guessing whether I used the proper terms: parameter vs argument, or vice-versa. Because if you can't distinguish parameter vs argument, esp. when working with callback/higher order functions, it's really easy to get lost. Someone please advise.