SHARE

Yo ninjas, in this asynchronous JavaScript tutorial, I’ll introduce you to promises. JavaScript promises are like placeholder objects for an action that will complete at some point in the future, and are a great way to organise our asynchronous code and callback functions.

—– COURSE LINKS:
+ Atom editor – https://atom.io/

———————————————————————————————
You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage…

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== JavaScript for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET

============ CSS for Beginners Playlist =============

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gQeDH6xYhmO-db2mhoTSrT

============== The Net Ninja =====================

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

================== Social Links ==================

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

23 COMMENTS

  1. There is one god damn thing that I can't understand, its the parameter of the callback function:
    If i understand correctly, a paremeter is just a placeholder for whatever argument we want to pass in the function. How does it know that the parameter "tweets" refers to whats in the "tweets.json" file. The name of the parameter is up to me, I can call it "tweets" or whatever I want, but how does it know what to pass in > How is "tweets" replaced by the content of the "tweets.json" file? By what argument the "tweets" parameter is getting replaced?

    $.get("data/tweets.json")
    .then(function(tweets){
    console.log(tweets);
    });

    Its probably dumb, but I can't visualize it.

  2. Great tutorial! The part where you say that promises are a placeholder for the result of an asynchronous action helped me fully understand the concept, as well as appreciate the usefulness of promises.

  3. Great job Net Ninja. So if Promises are already built into jQuery, and it's that short of a code block …. why would you use the first method?
    Because you can't use jQuery?

  4. What I'm not sure of: Does it make sense to use $.get() after using an AJAX call? They don't seem to be similar in that respect and I have a ton of ajax calls from coming live websites via API.

  5. as far as I understand we would enter the onerror clause if the data fails to retrieve due to eg malformed URL etc. however I cannot think of a circumstance under which we would enter the else clause of the onload. after all we've hit the endpoint and data was returned. would a 404 error for example enter the else clause of onload or would it enter onerror?

  6. Hey, I really appreciate these videos and it's very well explained. Thank you!

    Can I ask a question that is sort of related to this video?

    I've seen lots of nodeJS tutorials where people use an NPM library called Async. I cannot see what Async brings to the table that your method (shown above) cannot already handle.

    So, I'm trying to decide whether to use the NPM Async module (as I see in a few tutorials) or whether to use your method – which appears to be pure javascript.

    I'd be REALLY grateful if you could shine some light on this. Perhaps I'm missing something. Thank you!

  7. Do you have a github for these codes? If you have, can you put it in the description? BTW, your explanations are super clear and you are doing a great job. Subscribed to your channel.

LEAVE A REPLY

Please enter your comment!
Please enter your name here