What are JavaScript PROMISES? đŸ€ž

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 20. 12. 2023
  • #JavaScript #tutorial #courses
    // Promise = An Object that manages asynchronous operations.
    // Wrap a Promise Object around {asynchronous code}
    // "I promise to return a value"
    // DO THESE CHORES IN ORDER
    // 1. WALK THE DOG
    // 2. CLEAN THE KITCHEN
    // 3. TAKE OUT THE TRASH

Komentáƙe • 51

  • @BroCodez
    @BroCodez  Pƙed 7 měsĂ­ci +21

    // Promise = An Object that manages asynchronous operations.
    // Wrap a Promise Object around {asynchronous code}
    // "I promise to return a value"
    // PENDING -> RESOLVED or REJECTED
    // new Promise((resolve, reject) => {asynchronous code})
    // DO THESE CHORES IN ORDER
    // 1. WALK THE DOG
    // 2. CLEAN THE KITCHEN
    // 3. TAKE OUT THE TRASH
    function walkDog(){
    return new Promise((resolve, reject) => {
    setTimeout(() => {
    const dogWalked = false;
    if(dogWalked){
    resolve("You walk the dog 🐕");
    }
    else{
    reject("You DIDN'T walk the dog");
    }
    }, 1500);
    });
    }
    function cleanKitchen(){
    return new Promise((resolve, reject) => {
    setTimeout(() => {

    const kitchenCleaned = true;
    if(kitchenCleaned){
    resolve("You clean the kitchen đŸ§č");
    }
    else{
    reject("You DIDN'T clean the kitchen");
    }
    }, 2500);
    });
    }
    function takeOutTrash(){
    return new Promise((resolve, reject) => {
    setTimeout(() => {
    const trashTakenOut = true;
    if(trashTakenOut){
    resolve("You take out the trash ♻");
    }
    else{
    reject("You DIDN'T take out the trash");
    }
    }, 500);
    });
    }
    walkDog().then(value => {console.log(value); return cleanKitchen()})
    .then(value => {console.log(value); return takeOutTrash()})
    .then(value => {console.log(value); console.log("You finished all the chores!")})
    .catch(error => console.error(error));

    • @salimthedon
      @salimthedon Pƙed 10 dny

      Thank you bro!You made me understand promises!

  • @hamodi20091
    @hamodi20091 Pƙed 7 měsĂ­ci +27

    Finally, I understand PROMISES. Thanks

  • @gokhanozdemir8970
    @gokhanozdemir8970 Pƙed 4 měsĂ­ci +1

    Your video made promises clear in my head. Thank you for your effort.

  • @altlalit
    @altlalit Pƙed 6 měsĂ­ci +6

    It is the best explanation ever.
    Thanks

  • @SaintHanappi
    @SaintHanappi Pƙed 7 měsĂ­ci +19

    Take out the trash "is really quick" => open the window/door - throw the trash - close. 🙊 .... Thank you! Getting closer to understand. (The value in the end is a bit "confusing", but I will make some studies and samples.)

    • @BroCodez
      @BroCodez  Pƙed 7 měsĂ­ci +6

      async/await simplifies the process in the next topic

  • @Eteen12
    @Eteen12 Pƙed 4 měsĂ­ci

    This is super helpful, last night was having trouble wrapping my head around this but this video really made it click! Thanks man!

  • @rbsfinger
    @rbsfinger Pƙed 5 měsĂ­ci +1

    Bro, you rock. Thanks for the video!

  • @haidermansoor4760
    @haidermansoor4760 Pƙed 5 měsĂ­ci

    The best tutorial on promises. Thanks mannn

  • @anonymousguy6614
    @anonymousguy6614 Pƙed měsĂ­cem

    Legend. Such a hard concept to grasp, and after watching your video and following along closely, I understand Promises now. Entertaining, imo funny, and educational video. You never disappoint me. Thank you so much. You're awesome!

  • @engenheirodesoftware
    @engenheirodesoftware Pƙed 6 měsĂ­ci +1

    Very good thank you.

  • @jktrivedi29
    @jktrivedi29 Pƙed měsĂ­cem

    Wow, after watching many videos finally i understood. Thanks.

  • @lambo-ca
    @lambo-ca Pƙed 3 měsĂ­ci

    I finally fully understood. Thanks man.

  • @yy.u.i
    @yy.u.i Pƙed 3 měsĂ­ci

    Thank you, it was very clear and simple.

  • @mr.saiprasad5840
    @mr.saiprasad5840 Pƙed 6 měsĂ­ci

    The way of your explain is Awesome #BroCodez
    Thank You

  • @lillianirungu8180
    @lillianirungu8180 Pƙed 2 měsĂ­ci

    Wow thanks a lot. I was struggling to understand but now I do.

  • @mohantraju
    @mohantraju Pƙed 4 měsĂ­ci

    really helpful. Thanks

  • @itzvaibhavkumar3029
    @itzvaibhavkumar3029 Pƙed měsĂ­cem

    Man i love you sm i had such a hard time understanding callbacks and promises

  • @SuperDude101
    @SuperDude101 Pƙed 7 měsĂ­ci +1

    i just searched about this tomorrow and you uploaded it today what are the odds ;)

  • @rajatsachann
    @rajatsachann Pƙed 2 měsĂ­ci

    Youre a savior man!

  • @user-sf6ej7cl2t
    @user-sf6ej7cl2t Pƙed 3 měsĂ­ci

    Thank you, it really helped me

  • @renatocorreia1805
    @renatocorreia1805 Pƙed 6 měsĂ­ci

    THE BEST EXPLANATION

  • @mzedan2
    @mzedan2 Pƙed 4 měsĂ­ci

    Thank you very much

  • @open2003
    @open2003 Pƙed 3 měsĂ­ci

    You are awesome

  • @sekwayimokoena3225
    @sekwayimokoena3225 Pƙed 5 měsĂ­ci

    The best!

  • @oshadhaedirisinghe1455
    @oshadhaedirisinghe1455 Pƙed měsĂ­cem

    Thank you

  • @Jangidlksh1
    @Jangidlksh1 Pƙed 2 měsĂ­ci

    Yuuuhh, killed it mann

  • @bordercut1
    @bordercut1 Pƙed měsĂ­cem

    sharp.

  • @Pururin_Purin
    @Pururin_Purin Pƙed 6 měsĂ­ci +7

    Honestly I find the "pyramid of doom" less confusing than promises

    • @pidli
      @pidli Pƙed 4 měsĂ­ci

      😂😂😂😂 same

    • @jeremyfrias7
      @jeremyfrias7 Pƙed 4 měsĂ­ci +1

      😅 It gets easier with a lot of repetition
 It was hard to wrap my head around but just going back over and over and coding along simultaneously can & will do the trick.

  • @Granta_Omega
    @Granta_Omega Pƙed 25 dny

    2.5 seconds to clean the kitchen? Damn, that's a long time!

  • @beepboopitsjoop4678
    @beepboopitsjoop4678 Pƙed 7 měsĂ­ci +1

    where was this when i was banging my head against the wall learning this ;.;

    • @BroCodez
      @BroCodez  Pƙed 7 měsĂ­ci +4

      I was probably still recording it lol

  • @Ershaad-ss3uc
    @Ershaad-ss3uc Pƙed měsĂ­cem

    OO LA LA

  • @ShaileshKumar-re6yz
    @ShaileshKumar-re6yz Pƙed 2 měsĂ­ci +1

    Can you please explain the code you wrote inside the then() method. What does it do and why are we creating the arrow function with value parameter and how is it able to access the resolve value

    • @drewlee7435
      @drewlee7435 Pƙed 21 dnem

      When you pass the value into the resolve, that value parameter is what gets sent to the ".then()" function (as a parameter) written at the end of the file. Just how promises work

  • @rustyking23able
    @rustyking23able Pƙed 5 měsĂ­ci

    I noticed some tutorials will create a variable equally a new promise kinda like this "var p = new Promise((resolve, reject))" ... in your example you returned promises, is there a preferred way or this situational ?

  • @sedhunique
    @sedhunique Pƙed 20 dny

    So basiclly, we created async to make code run parallely,... then we found out that it caused some errors,... so we again create promises to make the async code, run sychronously 💀

  • @user-cup_-nu4kg
    @user-cup_-nu4kg Pƙed 6 měsĂ­ci

    Can you not method chain instead of returning the values of the promises?

  • @xXAngelmlXx
    @xXAngelmlXx Pƙed 2 měsĂ­ci

    I understood it, but you made it a little unclear than it should have. Using .then.then.then without returning anything would've been a little clearer maybe, but there are a few other ways.

  • @andrewchukwudumeje9413
    @andrewchukwudumeje9413 Pƙed 2 měsĂ­ci +1

    If the code is asynchronous why does the first reject prevent the other functions from being executed

    • @chomantsang3906
      @chomantsang3906 Pƙed 29 dny +1

      Because it promises to return a value, but the next function depends on the value.

  • @DamosyTheFreckle
    @DamosyTheFreckle Pƙed 18 dny

    Hi, why do we need the return when calling another chore?

  • @alexidino
    @alexidino Pƙed 4 měsĂ­ci +1

    how he do this 1:50 ? This little picture ?

  • @Matheus-mr4tl
    @Matheus-mr4tl Pƙed 17 dny

    this is more complicated and verbose than callback hell đŸ˜