What are JavaScript PROMISES? 🤞

2023 ж. 20 Жел.
31 774 Рет қаралды

#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

Пікірлер
  • // 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));

    @BroCodez@BroCodez4 ай бұрын
  • Finally, I understand PROMISES. Thanks

    @hamodi20091@hamodi200914 ай бұрын
  • 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.)

    @SaintHanappi@SaintHanappi4 ай бұрын
    • async/await simplifies the process in the next topic

      @BroCodez@BroCodez4 ай бұрын
  • This is super helpful, last night was having trouble wrapping my head around this but this video really made it click! Thanks man!

    @Eteen12@Eteen12Ай бұрын
  • It is the best explanation ever. Thanks

    @altlalit@altlalit4 ай бұрын
  • Your video made promises clear in my head. Thank you for your effort.

    @gokhanozdemir8970@gokhanozdemir8970Ай бұрын
  • Bro, you rock. Thanks for the video!

    @rbsfinger@rbsfinger3 ай бұрын
  • The best tutorial on promises. Thanks mannn

    @haidermansoor4760@haidermansoor47603 ай бұрын
  • I finally fully understood. Thanks man.

    @lambo-ca@lambo-caАй бұрын
  • Thank you, it was very clear and simple.

    @yy.u.i@yy.u.iАй бұрын
  • Very good thank you.

    @engenheirodesoftware@engenheirodesoftware3 ай бұрын
  • THE BEST EXPLANATION

    @renatocorreia1805@renatocorreia18053 ай бұрын
  • You are great!!!! Thanks a lot

    @bekytadese4466@bekytadese446624 күн бұрын
  • Youre a savior man!

    @rajatsachann@rajatsachann15 күн бұрын
  • The way of your explain is Awesome #BroCodez Thank You

    @mr.saiprasad5840@mr.saiprasad58404 ай бұрын
  • 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

    @ShaileshKumar-re6yz@ShaileshKumar-re6yz8 күн бұрын
  • i just searched about this tomorrow and you uploaded it today what are the odds ;)

    @SuperDude101@SuperDude1014 ай бұрын
  • Thank you, it really helped me

    @user-sf6ej7cl2t@user-sf6ej7cl2tАй бұрын
  • really helpful. Thanks

    @mohantraju@mohantrajuАй бұрын
  • The best!

    @sekwayimokoena3225@sekwayimokoena32253 ай бұрын
  • You are awesome

    @open2003@open200319 күн бұрын
  • Thank you very much

    @mzedan2@mzedan2Ай бұрын
  • Can you not method chain instead of returning the values of the promises?

    @user-cup_-nu4kg@user-cup_-nu4kg4 ай бұрын
  • 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 ?

    @rustyking23able@rustyking23able2 ай бұрын
  • Honestly I find the "pyramid of doom" less confusing than promises

    @Pururin_Purin@Pururin_Purin4 ай бұрын
    • 😂😂😂😂 same

      @pidli@pidli2 ай бұрын
    • 😅 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.

      @jeremyfrias7@jeremyfrias72 ай бұрын
  • 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.

    @xXAngelmlXx@xXAngelmlXx3 күн бұрын
  • If the code is asynchronous why does the first reject prevent the other functions from being executed

    @andrewchukwudumeje9413@andrewchukwudumeje94134 күн бұрын
  • where was this when i was banging my head against the wall learning this ;.;

    @beepboopitsjoop4678@beepboopitsjoop46784 ай бұрын
    • I was probably still recording it lol

      @BroCodez@BroCodez4 ай бұрын
  • how he do this 1:50 ? This little picture ?

    @alexidino@alexidinoАй бұрын
    • window key + > , for mac is CTRL + CMD + Space

      @hongquannguyen5532@hongquannguyen5532Ай бұрын
    • ​@@hongquannguyen5532 Thank you, very appreciate !

      @alexidino@alexidinoАй бұрын
    • thanks bud

      @abhishekvashistha4017@abhishekvashistha401728 күн бұрын
KZhead