Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

13,616 Points

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.