Understanding and Using JavaScript Promises

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 69

  • @mattjak7834
    @mattjak7834 5 років тому +5

    Thank you. It's a pleasure to watch such detailed and simplified for understanding materials. Thank you so much for your work.

  • @ahmedr.
    @ahmedr. 2 роки тому

    Bravo! Before I watched your video I was preconditioned that promise in Js is hard to grasp and understand. I got it after 20 min .. amazing content :)

  • @sameershrestha7818
    @sameershrestha7818 4 роки тому

    At 23:28, what happens when there is an error in the second .then?
    Won't the following .then get executed?
    It seems like the control flow moves to .catch whenever an Error is created. Is it so? And .then before .catch doesn't returns a promise, how can it work at all?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому

      Yes, if there is an error, it jumps to .catch and executes whatever is in .catch. So you need to make sure you include in .catch what you want to happen if there is an error. If you need to address errors individual, pass two functions to each .then.

  • @sameershrestha7818
    @sameershrestha7818 4 роки тому

    Does console.log(def) at 21:33 need to be asynchronous?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому

      Thanks for the question. It is asynchronous because it is in response to a promise, in the then statement.

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 роки тому +3

    This concept ain't so easy. It takes multiple iterations to master. I watch your videos more than once. This one is almost excellent!

  • @amguruprasath8037
    @amguruprasath8037 5 років тому +1

    Don of javascript == Sir, Steven Hancock.

  • @fanuel2198
    @fanuel2198 4 роки тому

    Thanks a lot! This was much easier for me to understand compared to other videos I watched

  • @germanduterte7110
    @germanduterte7110 4 роки тому

    Thank you for the deep explanation and simple example of what is promises in JavaScript

  • @ayasswain
    @ayasswain 5 років тому +1

    Wonderful tutorial on promises. Where is the code of asyncFunction( ) ? I mean the body of asyncFunction( ). Your voice is clear and the way you explain with example code is too good. The best teacher on javascript award goes to you :-) .

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 років тому

      Thanks for the positive feedback! The asyncFunction is in a separate JS file attached to the same HTML page. I just separated it to simulate a function that might not be a part of your own code.

  • @alexanderalancahutay4821
    @alexanderalancahutay4821 6 років тому +1

    I really understand what a PROMISE really is because of you. Simple explanation thank you so much..

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому +1

      Thanks for the feedback! That helps me continue doing this.

  • @NotPastelDreams
    @NotPastelDreams 4 роки тому

    I nearly gave up on Promises until I watched this video. Thank You so much

  • @nikhilkohli3064
    @nikhilkohli3064 6 років тому +4

    Hi Steve, can you please post the contents of asyncfunc() and asyncfunc2() ?

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому +8

      I don't remember the exact function but it was simply doing a settimeout I believe. Something like this:
      let asyncFunction = function() {
      return new Promise(function(resolve, reject) {
      setTimeout(function() {
      resolve(asyncFunction has been resolved");
      }, 5000)
      });
      };

    • @konstantinkkk8397
      @konstantinkkk8397 6 років тому +1

      @@AllThingsJavaScript finally I find it!!!! It was very important!!!!

  • @mage9264
    @mage9264 6 років тому +6

    Top teaching skills and resources.

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 роки тому +5

    I wish we could dine together! We could talk about how to dominate the world with javascript!

  • @konstantinkkk8397
    @konstantinkkk8397 6 років тому +7

    you have created asyncFunction() but why you do NOT show the content of it? I have not understood this lesson from the beginning :(

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому

      Is your question asking why I created the asyncFunction? Or is there something else you would like me to explain better?

    • @konstantinkkk8397
      @konstantinkkk8397 6 років тому +4

      @@AllThingsJavaScript when you type in asyncFunction () in browser it show Promise. What the content inside of asynkFunction ()?

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому

      asyncFunction just returns a promise. That is all. It sets a short timer and then returns a promise.
      If you haven't yet it may help to watch all the movies in the playlist: ua-cam.com/play/PLTo9PCskHpbHIDnzl8tRYldSCSQaFgAHd.html

    • @dheerajnaik6467
      @dheerajnaik6467 4 роки тому +1

      Hi Konstantin . . To answer your question , the tutor has set up those promises.

  • @suemendez5674
    @suemendez5674 5 років тому +1

    Promises kept, thanks for the lesson, have a good day.

  • @carlosfernandez6470
    @carlosfernandez6470 6 років тому +2

    Nice explanation thank you so much.👍👍

  • @zameeebasha
    @zameeebasha 6 років тому +4

    Excellent explaination Steve, you did not mention that promise.then() / catch() methods return a promise in turn, if I am not wrong.

  • @PixelTB
    @PixelTB 4 роки тому

    Thank you for explaining it well. But I just have one question, does the .then functions itself returns a promise? Because you chained the .catch function to the .then function.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому +1

      The then method doesn't return a promise, but may contain something that returns a promise.

  • @chrislopezzz
    @chrislopezzz 5 років тому

    Beautiful teaching .... well explained!

  • @sarveshsridhar4465
    @sarveshsridhar4465 4 роки тому

    getting an error, async function is not defined....help!

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому

      Can you post code? If you are trying to use the same code as the tutorial, remember I defined an async function in a different JS file.

    • @sarveshsridhar4465
      @sarveshsridhar4465 4 роки тому +1

      @@AllThingsJavaScript
      Sorry, I missed the function defined in the other JS file

  • @michelcmorel
    @michelcmorel 4 роки тому

    Great work. Thank you very much👍

  • @mukurajpoot6550
    @mukurajpoot6550 6 років тому

    Sir i am not able to understand ..a function that returns promise which converts the given array of string into uppercase and returns the result after n seconds, where n is the length of input array.

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому

      Which part are you having difficulty with? Have you viewed the entire playlist on promises?

  • @MrMarkgyuro
    @MrMarkgyuro 5 років тому

    so it is always better to convert data to json ?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 років тому +1

      When using fetch it is how you access the data. You use the json method to convert the data to a format you can work with.

    • @MrMarkgyuro
      @MrMarkgyuro 5 років тому

      @@AllThingsJavaScript thank you! n really precise video🤗

  • @kartp2869
    @kartp2869 6 років тому

    is it possible that output of one promise can be use as input for another promise. If yes can you direct me how to do that.

    • @kartp2869
      @kartp2869 6 років тому

      I must say the most meaning video on chaining. Thanks a lot and keep up the good work

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому

      Yes, you would do that by issuing another promise. Does that help?

  • @someoneoutthere1866
    @someoneoutthere1866 4 роки тому

    very well structured video ;)

  • @seebugaud7243
    @seebugaud7243 6 років тому

    Hello sir,
    Please tell me what is array-like object and how do create own array-like object?
    Am new in JavaScript

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 років тому

      An array like object is simply an object that has a length property and then some indexed properties. So it has features of an Array, but was not created with the array literal ([]) or array constructor (new Array()). I'm not sure why you would want to create one, just create an array. However, sometimes these are created for you. For example, a node list (when you select HTML nodes) and the arguments of a function are array like. Usually we convert array like objects to arrays in order to work with them. Here is a tutorial: ua-cam.com/video/avPIXAftj24/v-deo.html

  • @MrBenjjj6
    @MrBenjjj6 6 років тому +2

    Thank you!

  • @cjmarchi
    @cjmarchi 5 років тому +1

    Great! One thing that I find odd is..where is the asyncFunction () and asyncFunction2 () declarations?
    BTW, I love all your tutorials, please keep up the good work!

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 років тому +2

      They are in a separate JS file.

    • @NotPastelDreams
      @NotPastelDreams 4 роки тому

      @@AllThingsJavaScript That confused me as well

    • @anishkc1831
      @anishkc1831 4 роки тому

      @@AllThingsJavaScript what's inside asyncFunction () function ? I am curious to know about the promises codes written inside the function .

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому +1

      @@anishkc1831 It just has a setTimeout is all. It looks something like this:
      let asyncFunction = function() {
      return new Promise(function(resolve, reject) {
      setTimeout(function() {
      resolve("asyncFunction has resolved.");
      }, 4000);
      });
      };

    • @anishkc1831
      @anishkc1831 4 роки тому

      @@AllThingsJavaScript thank you for a great tutorials bundle with depth knowledge

  • @flifluflofli
    @flifluflofli 4 роки тому

    Can not believe from all my classes it the course where i get the closest of understanding it but hahah still the logic escape me terrible hey lol I will get it :)

  • @Behold-the-Florist
    @Behold-the-Florist 4 роки тому

    Dry-hole? :| Amazing video but that totally distracted me! xD

  • @vont8424
    @vont8424 4 роки тому

    for beginner, it's tough to understand the JS promises concept from this video. I only managed to get little understanding from this video.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому

      As a beginner I wouldn't suggest learning promises from the start. I would recommend starting with the basics first. Perhaps a book or a course to get the basics down and then you can add to it.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 роки тому

      If you are interested in my getting started course let me know. I'm not trying to sell this to you, I just think you would avoid a lot of frustration by learning the basics first. Good Luck! Stick with it!

  • @Arty47
    @Arty47 5 років тому

    cool

  • @Pareshbpatel
    @Pareshbpatel 3 роки тому

    2021-09-20}

  • @vinayn9110
    @vinayn9110 5 років тому

    The concept is easy, the syntax is confusing !! in JavaScipt so many brackets etc..etc... and all tutorials assume you known the syntax frustrating !!!

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 років тому

      Which syntax elements are confusing? We can help clarify it.

    • @vinayn9110
      @vinayn9110 5 років тому

      @@AllThingsJavaScript anonymous functions that have no name such as function(val) , is that a self evoking function?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 років тому +1

      @@vinayn9110 This is really considered a callback. I've got multiple tutorials on callbacks you may want to look at. This is a declared functions that is passed into another function; in this case the then method of a promise. The then method is then responsible for invoking that function. Callbacks can be a bit confusing, but are vary powerful. Here are links to a couple of tutorials: ua-cam.com/video/Nau-iEEgEoM/v-deo.html and ua-cam.com/video/tBjvWZn9fvs/v-deo.html

    • @vinayn9110
      @vinayn9110 5 років тому

      @@AllThingsJavaScript thank you very much.