JavaScript ASYNC/AWAIT is easy! ⏳

Поділитися
Вставка
  • Опубліковано 20 жов 2024
  • #javascript #tutorial #programming
    // Async/Await = Async = makes a function return a promise
    // Await = makes an async function wait for a promise
    // Allows you write asynchronous code in a synchronous manner
    // Async doesn't have resolve or reject parameters
    // Everything after Await is placed in an event queue
    async function doChores(){
    try{
    const walkDogResult = await walkDog();
    console.log(walkDogResult);
    const cleanKitchenResult = await cleanKitchen();
    console.log(cleanKitchenResult);
    const takeOutTrashResult = await takeOutTrash();
    console.log(takeOutTrashResult);
    console.log("You finsihed all the chores!");
    }
    catch(error){
    console.error(error);
    }
    }
    doChores();

КОМЕНТАРІ • 63

  • @BroCodez
    @BroCodez  10 місяців тому +27

    // Async/Await = Async = makes a function return a promise
    // Await = makes an async function wait for a promise
    // Allows you write asynchronous code in a synchronous manner
    // Async doesn't have resolve or reject set up as parameters
    // Everything after Await is placed in an event queue
    function walkDog(){
    return new Promise((resolve, reject) => {
    setTimeout(() => {
    const dogWalked = true;
    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);
    });
    }
    async function doChores(){
    try{
    const walkDogResult = await walkDog();
    console.log(walkDogResult);

    const cleanKitchenResult = await cleanKitchen();
    console.log(cleanKitchenResult);

    const takeOutTrashResult = await takeOutTrash();
    console.log(takeOutTrashResult);

    console.log("You finsihed all the chores!");
    }
    catch(error){
    console.error(error);
    }
    }
    doChores();

    • @uddipta03
      @uddipta03 7 місяців тому

      walkDog()
      .catch(error => {console.error(error); return error; })
      .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!")})
      // index.js:52 You DIDN'T walk the dog 🦮
      // index.js:53 You clean the kitchen 👨🏻‍🍳
      // index.js:54 You take out the trash 🚮
      // index.js:54 You finished all the chores!
      when if the a promise rejected still I can resolve rest of the promises using promise chaining
      but for async/await it will not happen? how I can make it happened in the same way?

    • @seephor
      @seephor 2 місяці тому

      I think you could have removed the explicit Promises in those chore functions and marked them as async then used the return/throw syntax to mimic the resolve/reject syntax since in practice we don't really create new Promsie objects. What's what the async function is for!

  • @TheComputerSciencestudent.
    @TheComputerSciencestudent. 10 місяців тому +11

    so good to see you still uploading thanks for the C# videos I am a freshmen in College as CS major and I learnt a a lot from your videos. Just wanted to say THANKS BRO!!

  • @martinfriday5481
    @martinfriday5481 5 місяців тому +3

    I have been squabbling with this for a loooonnng time, this tutorial was super helpful and very straight to the point, thank you soo much

  • @kopilkaiser8991
    @kopilkaiser8991 12 днів тому

    You are one of the best teachers on UA-cam. I understand so well listening to your lectures. It even feels satisfying and calming to just learn from you 😊.😂🤪

  • @Abood-wn1fi
    @Abood-wn1fi 2 місяці тому

    i really struggled with understanding async and await but you explained it too good. Thank youuuuu

  • @darrenharris5231
    @darrenharris5231 8 місяців тому

    Thank you for this! This was really clear to understand. I think seeing the Promise function and the resolve and reject parameter helped

  • @nysmulerecords4465
    @nysmulerecords4465 5 місяців тому +1

    short but perfect and easy to understand.
    Thanks for sharing good tips.

  • @metaobserver657
    @metaobserver657 9 місяців тому +4

    THE best JS instructionals

  • @Smurfis
    @Smurfis 4 місяці тому

    Seems like an error catching and resolving way of coding realistically giving you ways to output custom errors pretty cool actually thanks for this.

  • @iftyrahman2239
    @iftyrahman2239 3 місяці тому

    Thanks bro thanks.....You explained it so easily.....I love you brother .❤

  • @footy895
    @footy895 10 місяців тому +11

    Bro are you a full time youtuber or working for a company?,your coding skills are really good

  • @luciusrex
    @luciusrex 22 дні тому

    you made it easy! thanks for this!

  • @VeriousSmithIII
    @VeriousSmithIII День тому

    So clear! thank you!

  • @reggiehurley1479
    @reggiehurley1479 9 місяців тому +5

    bro correct me if i'm wrong but in the first ex that results in the "resolve is not defined" error that has nothing to do with async vs not async function

  • @yuvarajsingh7806
    @yuvarajsingh7806 6 місяців тому

    Thankyou sir your teaching style is awesome❤

  • @alexaldridge3454
    @alexaldridge3454 6 місяців тому

    Hey Bro Code great video. Once I have gotten concepts like this down what do I search up to learn how to attach like the true or false area so it can be changed with lets say an html on a website. or how do I make it so the console logs so a user off the app can see it in nice text? (I feel Javascript is in the background how can I make it so a user can interact with this in an app?) Cheers

  • @x..darkfate..x
    @x..darkfate..x 4 місяці тому

    short and crisp video thnx for sharing

  • @HallowByThy
    @HallowByThy Місяць тому

    when you said heres what happens when you run this code, i felt like a monster was going to jump out when it came back with an error lol.

  • @robeeeeen
    @robeeeeen 4 місяці тому

    This is much better than the last .then video and useful.

  • @rbsfinger
    @rbsfinger 8 місяців тому

    Very helpful. Thanks for the video.

  • @abdosamir_225
    @abdosamir_225 4 місяці тому

    you are brilliant man

  • @manuelvaal1257
    @manuelvaal1257 5 місяців тому

    Very much needed!❤

  • @yohannestsegaye6945
    @yohannestsegaye6945 7 місяців тому

    really helpful,Thank You sir

  • @Taofetch
    @Taofetch 10 місяців тому +2

    which tutorial playlist I should follow, this 2024 one or the older one?

    • @Taofetch
      @Taofetch 10 місяців тому +1

      I`m one hour passed in the full 8 course vid and stuck between choosing what to follow now

    • @BroCodez
      @BroCodez  10 місяців тому +9

      This playlist is the updated version

    • @Taofetch
      @Taofetch 10 місяців тому +1

      @@BroCodezthankyou and have a great day bro!

    • @laperplayz1388
      @laperplayz1388 10 місяців тому

      @@BroCodez can you do a new video with more advanced c++ concepts pls. like polymorphism, encapsulation, abstraction, etc. and also like vectors, the auto keyword, and concepts that are new to the current version of c++ please my fellow bro

  • @hunin27
    @hunin27 10 місяців тому +19

    i started learning node.js and im explding its too hard :((

    • @CoolestPossibleName
      @CoolestPossibleName 10 місяців тому +3

      Go programming language has made by life much easier

    • @NAMEYOUTUBER
      @NAMEYOUTUBER 10 місяців тому +6

      pls dont explde

    • @hunin27
      @hunin27 10 місяців тому

      ill try. i start to learn a bit more@@NAMEUA-camR

    • @ALLSTARDECOURO2
      @ALLSTARDECOURO2 9 місяців тому +1

      so did you learned it?

    • @hunin27
      @hunin27 9 місяців тому +3

      @@ALLSTARDECOURO2 yes

  • @antcannon
    @antcannon 6 місяців тому

    Is there a way to get the data from inside the async function saved to a variable for later use?

  • @mzedan2
    @mzedan2 7 місяців тому

    Thank you very much

  • @oninzhusmillo5318
    @oninzhusmillo5318 Місяць тому

    Can you do it in c#?

  • @oshadhaedirisinghe1455
    @oshadhaedirisinghe1455 4 місяці тому

    Thank you

  • @BIRBHUMBOY-yy8ne
    @BIRBHUMBOY-yy8ne 8 місяців тому

    Make a in depth asynchronous video

  • @axshat_in
    @axshat_in 10 місяців тому +1

    Is Next Js Is the future?

  • @gabrielzanda6890
    @gabrielzanda6890 9 місяців тому

    Lov u bro

  • @ALLSTARDECOURO2
    @ALLSTARDECOURO2 9 місяців тому

    good stuff

  • @alisanan9090
    @alisanan9090 10 місяців тому +4

    catch (error) {
    throw(error);
    }

  • @theodoregateret996
    @theodoregateret996 Місяць тому

    901 Antwan Squares

  • @BrightMalcolm-f3y
    @BrightMalcolm-f3y Місяць тому

    132 Howell Shoals

  • @JK-xo5mf
    @JK-xo5mf Місяць тому

    FUCKING THANK YOU !!!!!

  • @SeanBradt-w9b
    @SeanBradt-w9b Місяць тому

    441 Kohler Wall

  • @HuttAldrich-b5j
    @HuttAldrich-b5j 29 днів тому

    Geovanni Road

  • @Chae_boll
    @Chae_boll Місяць тому

    31/8/2024
    day 1: done ✅✅

  • @TrinhHuumanhTrinhHuumanh-jf1fz
    @TrinhHuumanhTrinhHuumanh-jf1fz 3 місяці тому

    Helo

  • @IsaacVita-v8c
    @IsaacVita-v8c Місяць тому

    36633 Rosario Fall