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 Create a Promise

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Do i need to remember this ?

Everything went over me, feels like the concept was thrown instead of explained, can somebody help me understand this concept, what is happening ?

I kind of feeling scared about moving forward after every video, that I might get stuck there for hours, and end up getting frustrated, I am not sure what should I do ?

5 Answers

Hi Karan, everything is hard at the beginning, especially when you are new to the concept, just keep in mind that you can also try to think on paper, so the concept sticks, and as you use it more often, it will be easier to understand, I went through the same when I started python here at Treehouse and now, it just sounds too easy.

Also, no programmer remembers everything in the language of their choice, you can go back to it at anytime when you need it , as long as you know that it is possible with your specific programming language an then revisit it as you need any refresher, also try to use it as offen as possible, so that is easier to remember next time.

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Hey Sergio Andrés Herrera Velásquez , thanks for the motivational message, hope that happens with me too, at the moment am bit scared, but hoping everything will eventually fall into right place as it happened with you

josephpatrickpotot
josephpatrickpotot
18,010 Points

Do not skip anything at this point. If anything is not clear better do further reading or repeat the video as if it will be highly relevant later on in the course.

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Hi josephpatrickpotot , Thankyou for the advice, but sometimes It gets really hard to understand and in the videos too, they bring up some new terms, which are not explained, so had to watch the same video again and again!!

I spent about 2 whole days or 16 hours on Promises when first learning. Now almost a year later I am still going over the course as a refresher and to 'fill in the missing gaps', although i'm much more comfortable than I was before.

Something like asynchronous programming is quite technical in principle. You don't necessarily have to remember all the technical details, but a 'good enough' understanding of the concepts of asynchronous programming is very important to working as a web developer (that is to say, a programmer or engineer who uses web technologies), in my opinion.

The important part is to create an 'internal working model' of how asynchronous programming works in the JavaScript runtime environment -- hence why this course starts with animated diagrams of the call stack, callback queue, event loop, etc.

My advice is:

  • Practice: Make small projects where you try to create an asynchronous program, and log different values to the console to see what is happening inside your program at different points. Test your hypotheses about how this all works.
  • Examine the topic from multiple angles: There are lots of tutorials on YouTube, etc, that will explain asynchronous programming in JavaScript in different ways. This can be very useful in giving a broad understanding of how this all actually works.

Remember: These days you can ask language models (generative AI like ChatGPT, etc) questions about how complex topics like asynchronous programming works. This can be extremely helpful for building that 'internal working model' of how these things actually work at runtime.

:)

James Edens
James Edens
723 Points

I got my trial by fire in promises from a NodeJS course. I had created an API that had callback hell to do several server calls in a row on the same data (as we did a few videos ago, but with a lot more code). It was a pain to manage. So when the course I was following went over Promises and I saw how beneficial they were, I was determined to refactor all my callbacks into promises. I spent hours learning and experimenting and in the end I had a solution that wiped out over 100 lines of codes and made it far cleaner to read. Sometimes, the best way to learn something is to have a NEED to learn it in the real world. This means creating your OWN projects! I never learn everything from the courses I watch, instead I get inspiration to use in my own projects, and in the course of doing my own projects THEN I learn.

A good way to learn promises is to forget about XMLHttprequests we learned earlier, and start using Fetch() which was introduced into the Web API around 2017. Fetch does the same thing (it sendd a request and gets a response from a server) BUT fetch() returns a promise, meaning you will have to learn to work with them. So if you go back to the videos where we queried the astronauts names and Wikipedia, try converting those AJAX requests to fetch requests. Use resources (NO programmer knows everything, ALL of them still use Google/Stackoverflow and more recently AI (chatGPT is decent about explaining lines of code).