async / await in JavaScript - What, Why and How - Fun Fun Function

Поделиться
HTML-код
  • Опубликовано: 19 июн 2024
  • 💖 Support the show by becoming a Patreon
    / funfunfunction
    async and await in JavaScript allows us to pause the execution of functions, and that allows us to write asynchronous code that reads like synchronous code.
    🔗 Code snippets from the episode
    gist.github.com/mpj/3f8bc0c6e...
    🔗 Promises video
    • Promises - Part 8 of F...
    🔗 Map video
    • Map - Part 2 of Functi...
    🔗 Inline evaluation plugin
    quokka.funfunfunction.com
    🔗 mpj on Twitter
    / mpjme
    🔗 Help translate the show to your language
    ruclips.net/user/timedtext_cs_p...
    Inside a function marked as async in JavaScript, you are allowed to place the await keyword in front of an expression that returns a Promise. When you do, the execution of the async function is paused until that Promise is resolved.
    The idea with async / await in JavaScript is to be able to write asynchronous code that flows like synchronous code.
    💛 Follow on Twitch
    We record the show live Mondays 7 AM PT
    / funfunfunction
    💛 Fun Fun Forum
    Private discussion forum with other viewers in between shows. www.funfunforum.com. Available to patron members, become one at / funfunfunction
    💛 mpj on Twitter
    / mpjme
    💛 CircleCI (Show sponsor)
    Robust and sleek Docker-based Continuous Integration as a service. I used CircleCI prior to them becoming a sponsor and I love that their free tier is powerful enough for small personal projects, even if they are private. Use this link when you sign up to let them know you came from here:
    circleci.funfunfunction.com
    💛 Quokka (Show sponsor)
    Wonder how MPJ evaluates JavaScript inline his editor. Quokka is the answer - use this link when you buy to let them know you came from here:
    quokka.funfunfunction.com
    💛 FUN FUN FUNCTION
    Since 2015, Fun Fun Function (FFF) is one of the longest running weekly RUclips shows on programming 🏅 thanks to its consistency and quality reaching 200,000+ developers.
    🤦‍♂️ The Failing Together concept is what makes FFF unique. Most coding content out there focus on step-by-step tutorials. We think tutorials are too far removed from what everyday development is like. Instead, FFF has created a completely new learning environment where we grow from failure, by solving problems while intensively interacting with a live audience.
    Tutorials try to solve a problem. Failing Together makes you grow as a developer and coworker.
    📹 Each show is recorded live on Twitch in a 2-hour livestream on Mondays. The host, assisted by the audience, is tasked to complete a programming challenge by an expert guest. Like in the real world, we often fail, and learn from it. This, of course, reflects what the audience identifies with, and is one of the most praised aspects of the show.
    ⏯ On Fridays, an edited version of the show is adapted for and published on RUclips.
    Content Topics revolve around: JavaScript, Functional Programming, Software Architecture, Quality Processes, Developer Career and Health, Software Development, Project Management
  • НаукаНаука

Комментарии • 761

  • @alexongg
    @alexongg 6 лет назад +30

    Jo Mat, where's the link to become a patreon?

    • @funfunfunction
      @funfunfunction  6 лет назад +11

      +Alejandro Corredor the patreon launches on Friday morning, 0800 GMT!

    • @alexongg
      @alexongg 6 лет назад +1

      Fun Fun Function awesome, looking forward to it man.

    • @teo_sk
      @teo_sk 6 лет назад +2

      Can't wait for my BADJE

  • @junkgrave
    @junkgrave 6 лет назад +7

    This episode had everything I love about FunFunFunction - COFFEE, antics, and the usage of refactoring the same function multiple ways to illustrate concepts. I'm excited that you're going to be investing more time in your channel!

    • @funfunfunction
      @funfunfunction  6 лет назад +2

      Hey J! Thanks a lot for the praise! I really appreciate comments like this that are specific about what you like, it's both so nice and helpful!

  • @lastnamefirstname2390
    @lastnamefirstname2390 6 лет назад +14

    "It will absolutely positively not be worth your money." I'm sold. I need that badge.

    • @funfunfunction
      @funfunfunction  6 лет назад +7

      Yes! I was betting that other peoples brain works like mine when writing that part of the script.

  • @johnstarich
    @johnstarich 6 лет назад

    This was probably my favorite episode of FunFunFunction to date! The content was presented very well, the pace was on point, and the antics were excellent comedic relief. I've watched many of your videos, but this one stood out to me as being especially well-made. To me, it had just the right amount of explanation paired with just the right amount of "stream of consciousness" programming.
    Thank you for your great work and I can't wait to watch more!

  • @robertomunoz9745
    @robertomunoz9745 5 лет назад +2

    4:32 after 2 days trying to understand, 10 seconds of explanation finally openned my mind... thanks bro

  • @AmanGupta_Dev
    @AmanGupta_Dev 6 лет назад +31

    You are so funny :D.. I have never seen any developer of this humour ! Thanks for teaching us WITH such as great sense of humour :)

  • @Shambo271
    @Shambo271 6 лет назад

    I'm continually impressed that you can make me laugh while educating me on programming! Your presentation and editing communicate why programming is NOT boring, which is a difficult thing to communicate to non-programmers. Well done!

  • @jnfsmile
    @jnfsmile 6 лет назад +114

    What takes longer - editing the video, or cleaning up the coffee?

    • @funfunfunction
      @funfunfunction  6 лет назад +96

      haha, the cleanup doesn't take too much time actually, perhaps 20 minutes. Editing this one took over 8 hours. :)

    • @user-lm7es8mr7s
      @user-lm7es8mr7s 6 лет назад +6

      That sh1t scared me.

    • @bensisakht7076
      @bensisakht7076 6 лет назад +2

      I wonder how much papers you go through for those pop ups lol ; awesome & funny , thanks

    • @rafadydkiemmacha7543
      @rafadydkiemmacha7543 4 года назад

      Fun Fun Function if editing a video like this one takes you 8 hours, you do something wrong, bro.

  • @JB-ux3ri
    @JB-ux3ri 4 года назад

    Thank you, I just watched all 10 of your functional programming videos, they were very good. You make it a lot more interesting/bearable than other teachers I've listened to.

  • @badselection94
    @badselection94 4 года назад

    Without a doubt one of the best, nay, THE best introduction to a tutorial I have ever had the pleasure of viewing.

  • @mazyvan
    @mazyvan 6 лет назад +1

    Love it! Please more videos like this. I was starting to miss them

  • @richardnorris9030
    @richardnorris9030 6 лет назад +1

    Was waiting for a youtube channel like this, almost did it myself but no way was going to do it like this, been watching a while, you are doing it so right! Awesome stuff...

  • @monozub
    @monozub 6 лет назад

    Hi MPJ, awesome stuff! I had a similar feeling about async/await up to the moment when I had to use recursion, this is where it really shines.

  • @michaeljenis8707
    @michaeljenis8707 5 лет назад

    Very well done! Thank you for clearing this up and showing me how to mix vanilla Promises + async await!

  • @user-kj1ih9uc7k
    @user-kj1ih9uc7k 6 лет назад

    I missed this format of your video. Thank you for you work. I remember last summer when I was learning ES6 from your videos and then I got the job. Thank you. You probably made a big influence on my life and this is awesome.

  • @SayuStrife
    @SayuStrife 6 лет назад +15

    Production quality keeps improving keep apon week. Nice job!

  • @sergiov1828
    @sergiov1828 6 лет назад +6

    Loved the reference to FF6's victory music, I gained a programming level watching this video!

  • @maronov
    @maronov 6 лет назад +2

    Hey MPJ, love your videos. Very absorbing, concise, and entertaining. I've been coding JS professionally since 2012, and watching this series is helping renew my passion for the language. Keep up the great work! FYI I hit the Subscribe button right around when I heard the FFV victory music at 6:53 :-)

  • @sachindraragul1094
    @sachindraragul1094 2 года назад

    Man!!. I'm using async await for about an year but still your video gives me a stronger understanding of async await. Would love to see you again in this channel.

  • @artemsh6853
    @artemsh6853 6 лет назад +13

    Hi MPJ! I'm FE developer from Kyiv. Your videos are amazing, thanks for all your educational efforts!

    • @funfunfunction
      @funfunfunction  6 лет назад +14

      Thank you so much for your kind words, Artem! гарного тижня!

  • @PaoloTamburini
    @PaoloTamburini 4 года назад +5

    Hi, you’re very nice and funny, but I found you extremely clear and easy to follow. Moreover learning smiling is the best way! You’re unique! Very good job!

  • @qwarlockz8017
    @qwarlockz8017 6 лет назад +1

    MPJ!!!! You Rock! Glad you are back! We ALL missed you! I go back and watch your old vids as refreshers on different topics. You make code fun! Keep up the great work and you know... I LOVED the opening! (and I am way high on the OCD spectrum! ) Cant WAIT to see the next installment!

    • @qwarlockz8017
      @qwarlockz8017 6 лет назад

      Oh and by the way.. yes I will DEF be keeping a sharp eye out on Friday! Best of luck in making this a full time gig! I totally think this is a worth while cause. Again, Dude, you make code fun!

  • @AndreBradshaw
    @AndreBradshaw 6 лет назад

    I stopped at 7:43 as recommended, but the first 7 minutes was great! Thanks! Best explanation of async await I have seen.

  • @kendowney6009
    @kendowney6009 6 лет назад +1

    Love these videos, MPJ. Your humor and animation make dry subjects fun to learn.

    • @hiexis
      @hiexis 5 лет назад

      when i see dry, the first thought come into mind was like 'DRY '...

  • @donfrolic
    @donfrolic 6 лет назад

    Congrats to your new job :) Very well deserved.
    Excellent episode. Your videos are consistently getting better and better!
    Also looooove the intro !!!

  • @kirsanov2008
    @kirsanov2008 6 лет назад

    What I like about FFFn is that MPJ not only talking about stuff, he also explaining it using opposite examples! Hell yeah man!

    • @funfunfunction
      @funfunfunction  6 лет назад +1

      Thanks! I really like when people call out specifics about what they like, really helps when improving the show.

  • @monkkokkalis1354
    @monkkokkalis1354 6 лет назад

    High-quality content as usual, MPJ. Thank You!

  • @selbeezy
    @selbeezy 6 лет назад +1

    Great job explaining! I'm having a talk in two weeks about refactoring stuff into using async / await, and found the way you presented stuff hugely helpful =)

  • @NdaJret
    @NdaJret 6 лет назад

    Hey Npj! I think the most important think you glossed over was how async await makes error handling much more sane now. You can wrap your awaits in it's own try catch which is a super win!

  • @javajoint
    @javajoint 6 лет назад +1

    I'm glad that the flying visual aids (cards) are back!

  • @docmars
    @docmars 6 лет назад +3

    Good on you for making this a paid gig! Always been a fan, and I wish you the best success MPJ :)

  • @denisangelov4629
    @denisangelov4629 6 лет назад

    This is probably the best of all your videos that I have seen so far. Good job

  • @JDJ1213
    @JDJ1213 5 лет назад +1

    amazing quality, entertaining and an excellent presentation. Well done.

  • @sweeball
    @sweeball 6 лет назад

    Excellent as usual mpj. Thanks for teaching me Async/Await. I think the Patreon scheme is also a great way to help to sustain these quality shows. So I'm in!

  • @alessandro-desimone
    @alessandro-desimone 6 лет назад

    This is one of the best episodes you've made. thanks!

  • @lgong2667
    @lgong2667 6 лет назад +8

    11:47 "result" is not an array of urls. it is a promise that will resolve to an array of urls.
    20:13 the "await" before "Promise.all" seems unnecessary since "await Promise.all" resolves to the url array, but the "fetchCatAvatars" async function will wrap the url array with a new promise after return. Instead, without the await, the "fetchCatAvatars" async function will just return a promise that mirrors the promise returned by "Promise.all".

  • @subota23
    @subota23 6 лет назад +9

    Great explanation! Also like for inline evaluation plugin.

    • @x-lightsfs5681
      @x-lightsfs5681 5 лет назад

      Idk what is the inline evaluation pmuggin. Can u explain me please?

  • @diegocantelli
    @diegocantelli 5 лет назад

    The best video about async in js so far. Thanks man!

  • @laurenbuxton2145
    @laurenbuxton2145 6 лет назад

    love the high quality of your videos and the speed you talk

  • @JamesDHarrington
    @JamesDHarrington 6 лет назад

    I was right there with you for a while. "Why not just use promises?" but you have enlightened me. Thanks!

  • @georgesaeid7231
    @georgesaeid7231 6 лет назад

    Thank you, this is the best explanation ever on the web for async/await.

  • @libry-toolbox3674
    @libry-toolbox3674 3 года назад +1

    Absolutely wonderful video. Great explanation of async and await. The insanity makes it astoundingly fun super entertaining. I love that *_Teaching is the best way to learn_*

  • @liamsutton6202
    @liamsutton6202 6 лет назад

    The cleanup for that intro would give me nightmares!, brilliant as always :D

  • @claudesveganchannel910
    @claudesveganchannel910 6 лет назад +10

    Wow MPJ, really proud about you, I'm glad that you are working more on your own things, you truly deserve it. You put out really great content mate, keep it going and congrats on the new projects :)

  • @reristavi
    @reristavi 6 лет назад

    You're such a good teacher and Entertainer. Thank you.. And yeah... Gosh... promises took hell out of my life...

  • @youtweek
    @youtweek 6 лет назад

    Best coding channel on RUclips. Thanks for your excelent work ;)

  • @EduardoRFS
    @EduardoRFS 6 лет назад

    best part "quokka is the inline evaluation" thx man, i love u

  • @agustinortiz4743
    @agustinortiz4743 6 лет назад

    The nesting async await calls was super helpful! Thanks!

  • @bensisakht7076
    @bensisakht7076 6 лет назад

    Great Job MPJ! Wish my early exposure to programming were made by someone like you ; had a dead boring start many years ago which caused me years of resistance to joine this boat .. though am enjoying it now .. Cheers!

  • @bundyfx
    @bundyfx 6 лет назад +1

    Man, these new MPJ intro's are on point!

  • @livarion
    @livarion 5 лет назад

    This if f*ng amazing. I love this video. It's explanatory, engaging, full of energy and enthusiasm, presenting the topic in a clear way - well done. I wish for more videos like this in the future : )

  • @BlackSagres
    @BlackSagres 6 лет назад +3

    Bold move, dude. Wish you all the luck, and keep awesome content flowing!

  • @wmhilton-old
    @wmhilton-old 6 лет назад +5

    Best coffee scene yet!

  • @pierread1011
    @pierread1011 6 лет назад

    Another excellent video MPJ, I've been meaning to watch this for a while... Glad I did. I had the same feeling as you about async/await initially (ie. something like "what's the use?") but actually, this can be interesting indeed eventually! Thanks a lot.

  • @fauzialaziz7570
    @fauzialaziz7570 5 лет назад

    Thank you, kind sir, you make me more understand about this stuff. I hope you have a good day :)

  • @RafaelRibeiro
    @RafaelRibeiro 5 лет назад

    That was a great explanations about async await functions. Thanks

  • @nabilmediouni5069
    @nabilmediouni5069 4 года назад +1

    Hello, thanks so much for the video. I wanted to ask about the extension that you're using to preview the log directly in VS Code?

  • @redgreenbluehex
    @redgreenbluehex 6 лет назад

    Great video. Thanks for teaching me something new!

  • @asterixcode
    @asterixcode Год назад

    you are great, amazing teacher and a funny dude! Thanks for all your videos, I've learned so much from it.

  • @PhuNguyen-bi7pi
    @PhuNguyen-bi7pi 5 лет назад

    haha, I couldn't imagine learning programming can be fun like this. Thanks!

  • @Rashomon69
    @Rashomon69 6 лет назад

    I'd never heard of Quokka before. It looked awesome in your video, so I looked it up. I'm going to install and use it. I'm stoked! Thanks for teaching me something new... yet again. :)

  • @rafaeldonascimento5104
    @rafaeldonascimento5104 6 лет назад +1

    Intro is great! lol
    As usual, your videos help me a lot learning javascript. (Yeah, that means I might be willing to become a patron. =P)
    To me, seems like async wait is more like an easy way to write nested promises, which appears to be pretty commom and hard to read (at least in my study projects).

  • @MiguelMartinez-xx2zy
    @MiguelMartinez-xx2zy 6 лет назад +2

    What a really good video, thank you so much!

  • @MartinPultz
    @MartinPultz 6 лет назад +2

    Also worth pointing out the use of try/catch so errors can be handled if the await fails. You can still use then/catch so best to choose, which you prefer.
    public async getSomething() {
    try {
    const data = await this.restCall();
    console.log('success', data);
    } catch (error) {
    console.log('whoops', error);
    }
    }

  • @nathand8401
    @nathand8401 6 лет назад

    Learning code from an Erik Karlsson lookalike really brings together both of my hobbies. Thanks for the great video!

  • @baltaza
    @baltaza 3 года назад

    You are one of the greatest teachers ever. Thank you

  • @DimoDimov1
    @DimoDimov1 6 лет назад

    Mate! This video is gold! Thank you so so much! I finally get it :D

  • @billiii96
    @billiii96 6 лет назад

    Congrats ! You won a big fan !
    Your work is amazing, where have you been all my life ?

  • @busyrand
    @busyrand 4 года назад

    Great video! That 'Quokka' tool looks very useful. It allows you to troubleshoot through console.logs in real-time on the fly.

  • @56k-web
    @56k-web 6 лет назад +1

    Another funny video fully worth it's viewing time. I like your energetic style. I am greedy to get more informations about your further plans with "fun fun *".

  • @raducostache8342
    @raducostache8342 6 лет назад

    OMG that was the most hilarious introduction on a programming tutorial :))

  • @elioriba711
    @elioriba711 4 года назад +2

    Quick question, which snippet or library are you gonna use to display live the variable result on the right hand side like shown in the video?

  • @ComisarioLobo
    @ComisarioLobo 6 лет назад

    Wow, thanks for such a great video and for showing Quokka in action ;)

  • @rindiainvestments9878
    @rindiainvestments9878 6 лет назад +1

    Great video! I'm glad you pointed out the logical non-equivalence; else I was gearing up to leave an angry comment.
    Pro tip: to comment a section of code, select them (doesn't have to be perfect end-to-end selection, just the selected text has to span over those lines) with mouse, and hit Cmd + /. This is pretty standard across VSCode, Atom, Sublime etc.
    In fact, it works both ways - it also uncomments a selected portion, if it was previously commented like this.

    • @funfunfunction
      @funfunfunction  6 лет назад +3

      That's a great tip for coding on your own. I do, however, intentionally avoid editor trickery in the videos - partly because I don't want things to go too fast, and partly because it distracts from the main topic in the sense that people wonder how I did things, and I have to do a segueway to explain the hotkey every time I use it.

    • @rindiainvestments9878
      @rindiainvestments9878 6 лет назад +1

      Ah, my mistake. Hadn't thought of that :)

  • @Davidlavieri
    @Davidlavieri 6 лет назад

    Papers are back, wild electro swing musics appears. You are doing great MPJ

  • @kl1tU5
    @kl1tU5 6 лет назад

    Nice way to introduce to async/await... Thanks for share the knowledge

  • @RobertoNietoSal
    @RobertoNietoSal 6 лет назад

    Very clear, thank you for the video !

  • @Mrdisaster09
    @Mrdisaster09 6 лет назад

    subscribed... *as i was watching 'man this guy is amazing'.... the video was super fun and educational, ill be coming back for more :)

  • @ToniLiem
    @ToniLiem 5 лет назад

    you are not doing it like everyones else dude. and it AWESOMEEEEE....!!!

  • @thomasyates1630
    @thomasyates1630 4 года назад

    your teaching style is so good. A+++++

  • @atulkumar458
    @atulkumar458 5 лет назад

    Thanks for sharing this, Really nice explanation

  • @ariel_alves_dutra
    @ariel_alves_dutra 4 года назад

    Perfect explanation!! Thank you!

  • @lunaceee
    @lunaceee 6 лет назад

    Just became a patron. Keeping up with the good work! :) ... And can't wait to see my special badge.

  • @wanafnanhariz7650
    @wanafnanhariz7650 5 лет назад

    dude when u doing coffee , i immediately click the liked button - thx for the humour, u made my day ! haha

  • @wachidmudiwaluyo182
    @wachidmudiwaluyo182 5 лет назад

    Very great and intereating video, especially the part when you said "Why are you watching this video, go out and look at nature" 😂, this is why the channel name is Fun Fun Function

  • @unautrejoureneurope
    @unautrejoureneurope 6 лет назад

    Looking forward to know more about your FunFunForum ;) Keep doing the great work!

    • @funfunfunction
      @funfunfunction  6 лет назад

      I'm really looking forward to it too! It's going te be great. And thanks, I will!

  • @awsysumer3814
    @awsysumer3814 6 лет назад

    Lol, Petyr Baelish has switched into programming! though, he's AWESOME at it!
    thanks buddy! your explanation is one of the best i've ever seen! crystal clear!

  • @ChrislyBear
    @ChrislyBear 6 лет назад +6

    Hey MPJ,
    Why do we need to call await a second time after we await the response? The function already has paused and waited for the result of fetch. Why is there the need for a second await to get the data object?
    Chris

    • @funfunfunction
      @funfunfunction  6 лет назад +7

      +Chrisly3ear you get the response object when you get the headers. Ie you're not guaranteed to have the body at that time. That is why response.json() returns a promise that resolves to the body instead of the actual body.

    • @ChrislyBear
      @ChrislyBear 6 лет назад +2

      Makes sense. Thanks!

  • @ramakrishnanvairavasamy
    @ramakrishnanvairavasamy 4 года назад

    Really nice your facial expression with clear explanation....Thanks for your course

  • @Ruby-od2wn
    @Ruby-od2wn 5 лет назад

    Awesome explanation.. Thanks for sharing this.

  • @ghusse
    @ghusse 6 лет назад +1

    Thanks for this great episode on async await. One thing I would like to know is best practices of error handling with async await. My intuition is that it is easier to catch at the end of a promise than using try/catch blocks. But I'm interested by feedbacks on this subject.

    • @funfunfunction
      @funfunfunction  6 лет назад +1

      Yep, many people want to know about error handling, might be a great follow up.

  • @sagarmunjal
    @sagarmunjal 5 лет назад

    One of the best videos on this topic

  • @tabithae3679
    @tabithae3679 2 года назад

    Thank you for all you do. 💜💜💜

  • @NABZ028
    @NABZ028 6 лет назад

    Hi mmpj. Another great video. I was confused with async/await vs promises and now it's clear. Thanks and cannot wait for friday morning to get the special badge :-)

    • @funfunfunction
      @funfunfunction  6 лет назад +1

      Hi Johnny! So glad that I've managed to explain it well enough, and thank you so much for your support, it really means a ton, especially at this early stage.

  • @NixAlaister
    @NixAlaister 6 лет назад

    YES! MORE FFF! Always love the coffee breaks :)

  • @MrIgorbpf
    @MrIgorbpf 6 лет назад

    Very good video, man! Really helped me out!!!!

  • @henriquegiuliani9001
    @henriquegiuliani9001 6 лет назад

    Very nice video! I started using Quokka but it's not showing the inline outputs. Is there any additional config?
    Thanks!

  • @FuerMehrDemokratie
    @FuerMehrDemokratie 6 лет назад

    That is so brave. I ll keep watching you! :)

  • @zimbot1990
    @zimbot1990 6 лет назад

    Hi, Thanks for your videos !
    Just one thing, I think you should consider handling rejection, the code with `await / async` will be a little bit less elegant with a `try{} catch{}`
    Good continuation

  • @maiquerosa8963
    @maiquerosa8963 6 лет назад

    Wonderful explanation, Thanks