title
Async + Await in JavaScript, talk from Wes Bos

description
Flow Control in JavaScript is hard! Native Promises in JavaScript have helped immensely, but the syntax is still a little callback-y. With Async + Await, we can write synchronous looking code without losing any of the benefits of JavaScript's asynchronous nature. Wes Bos explores how async + await works, best practices for flow control, and explores several solutions for handling errors. Filmed at https://2017.dotjs.io on December 1st in Paris. You can follow Wes Bos on Twitter: https://twitter.com/wesbos This talk is under the creative commons license. freeCodeCamp is not associated with this talk. We're just excited to bring more exposure to to it! -- Learn to code for free and get a developer job: https://www.freecodecamp.com Read hundreds of articles on programming: https://medium.freecodecamp.com

detail
{'title': 'Async + Await in JavaScript, talk from Wes Bos', 'heatmap': [{'end': 166.365, 'start': 141.694, 'weight': 0.784}, {'end': 279.815, 'start': 255.855, 'weight': 0.78}, {'end': 408.992, 'start': 379.356, 'weight': 0.907}, {'end': 499.985, 'start': 473.134, 'weight': 0.718}, {'end': 610.777, 'start': 581.59, 'weight': 1}], 'summary': 'Covers async await in javascript, emphasizing its role in flow control and promise foundation with a real-life analogy. it also discusses handling asynchronous functions, promise chains, error handling, and best practices, including the creation of a handleerror high-order function and techniques to prevent app shutdown in node.', 'chapters': [{'end': 134.43, 'segs': [{'end': 96.876, 'src': 'embed', 'start': 9.977, 'weight': 0, 'content': [{'end': 12.098, 'text': 'Hey everyone, thanks so much for coming out today.', 'start': 9.977, 'duration': 2.121}, {'end': 15.238, 'text': 'My name is Wes Boss, I come all the way from Canada.', 'start': 12.118, 'duration': 3.12}, {'end': 22.4, 'text': 'I did actually grow up learning French, so if you want to try to talk to me in some French Canadian, I might be able to understand.', 'start': 15.799, 'duration': 6.601}, {'end': 30.623, 'text': "Here today, I'm going to talk to you about async await, and the reason why I want to talk to you about, yes, thank you, somebody laughed at that joke.", 'start': 23.321, 'duration': 7.302}, {'end': 35.344, 'text': 'Can we just take a second to appreciate my hilarious joke? Thank you, thank you.', 'start': 31.383, 'duration': 3.961}, {'end': 41.276, 'text': "I want to talk to you about async await today because flow control in JavaScript, it's really hard.", 'start': 36.893, 'duration': 4.383}, {'end': 47.841, 'text': 'So how many of you, show of hands, how many of you are using promises in your code day-to-day right now? Okay, cool, quite a few.', 'start': 42.277, 'duration': 5.564}, {'end': 52.684, 'text': "I'm going to go a quick review through promises just because this is the foundation of async await.", 'start': 47.861, 'duration': 4.823}, {'end': 59.509, 'text': "Promises in JavaScript are sort of like an IOU for something that's going to happen at some point in the future.", 'start': 53.124, 'duration': 6.385}, {'end': 64.147, 'text': 'So this could be an Ajax call returning data.', 'start': 61.044, 'duration': 3.103}, {'end': 69.993, 'text': "This could be accessing a user's webcam once they hit the Allow button on the little pop-up that shows.", 'start': 64.167, 'duration': 5.826}, {'end': 71.874, 'text': 'It could be resizing an image.', 'start': 70.033, 'duration': 1.841}, {'end': 80.102, 'text': 'The point is that all of these things take time, and with promises, we simply kick off the process, and then we move along with our lives.', 'start': 72.235, 'duration': 7.867}, {'end': 84.967, 'text': 'We only come back to that thing when we need to deal with the data.', 'start': 80.142, 'duration': 4.825}, {'end': 91.872, 'text': "So, but why do we do it this way in JavaScript? And that's because JavaScript waits for nobody.", 'start': 85.447, 'duration': 6.425}, {'end': 96.876, 'text': 'It simply, everything in JavaScript is asynchronous,', 'start': 91.892, 'duration': 4.984}], 'summary': 'Wes boss discusses async await and the importance of promises in javascript, with a focus on flow control and practical use cases. he engages the audience and shares his expertise from canada.', 'duration': 86.899, 'max_score': 9.977, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo9977.jpg'}], 'start': 9.977, 'title': 'Async await in javascript', 'summary': 'Discusses the concept of async await in javascript, highlighting its significance in flow control and promise foundation, with a real-life analogy to illustrate asynchronous programming.', 'chapters': [{'end': 134.43, 'start': 9.977, 'title': 'Async await in javascript', 'summary': 'Discusses the concept of async await in javascript, emphasizing its importance in handling flow control and the foundation of promises, with a focus on the asynchronous nature of javascript. it also uses a real-life analogy to illustrate the concept of asynchronous programming.', 'duration': 124.453, 'highlights': ["Promises in JavaScript are like an IOU for future events, such as Ajax calls or accessing a user's webcam, and they are foundational to async await.", "JavaScript's asynchronous nature is highlighted, emphasizing the need to kick off processes and deal with the results accordingly, similar to real-life activities like making coffee and cooking breakfast.", 'The speaker, Wes Boss, introduces himself and the topic of async await, engaging the audience by relating to his background and using humor to capture their attention.', 'The audience engagement is observed as the speaker interacts with the attendees, making a lighthearted joke and conducting a show of hands to gauge the usage of promises in their daily coding activities.']}], 'duration': 124.453, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo9977.jpg', 'highlights': ['Promises in JavaScript are foundational to async await, serving as an IOU for future events.', "JavaScript's asynchronous nature emphasizes the need to kick off processes and handle results, akin to real-life activities.", 'Wes Boss engages the audience by relating to his background and using humor to capture their attention.', 'The speaker interacts with the attendees, making a lighthearted joke and conducting a show of hands to gauge promise usage.']}, {'end': 581.59, 'segs': [{'end': 172.708, 'src': 'heatmap', 'start': 141.694, 'weight': 0.784, 'content': [{'end': 143.415, 'text': 'And we would write code that looks like this.', 'start': 141.694, 'duration': 1.721}, {'end': 146.856, 'text': "We've all written terrible, terrible code that probably got a little bit more.", 'start': 143.475, 'duration': 3.381}, {'end': 149.598, 'text': 'It looks like a Christmas tree if you go on the side.', 'start': 146.876, 'duration': 2.722}, {'end': 156.541, 'text': "What's really cool about that is that promises allow us to start writing code like this, where we can run our functions, make coffee, make breakfast,", 'start': 150.498, 'duration': 6.043}, {'end': 161.503, 'text': 'and they return a promise, not the data a promise that the data will come at some point in time.', 'start': 156.541, 'duration': 4.962}, {'end': 166.365, 'text': 'And then we can use .then to listen for the data actually coming back.', 'start': 161.863, 'duration': 4.502}, {'end': 172.708, 'text': 'We can take it one step further and sort of wrap it in a mega promise by saying promise.all,', 'start': 166.425, 'duration': 6.283}], 'summary': 'Promises in code allow for asynchronous handling and efficient execution of multiple tasks.', 'duration': 31.014, 'max_score': 141.694, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo141694.jpg'}, {'end': 178.89, 'src': 'embed', 'start': 150.498, 'weight': 0, 'content': [{'end': 156.541, 'text': "What's really cool about that is that promises allow us to start writing code like this, where we can run our functions, make coffee, make breakfast,", 'start': 150.498, 'duration': 6.043}, {'end': 161.503, 'text': 'and they return a promise, not the data a promise that the data will come at some point in time.', 'start': 156.541, 'duration': 4.962}, {'end': 166.365, 'text': 'And then we can use .then to listen for the data actually coming back.', 'start': 161.863, 'duration': 4.502}, {'end': 172.708, 'text': 'We can take it one step further and sort of wrap it in a mega promise by saying promise.all,', 'start': 166.425, 'duration': 6.283}, {'end': 178.89, 'text': 'and that will allow us to wait until both of those things are done, until we go forward and deal with the result.', 'start': 172.708, 'duration': 6.182}], 'summary': 'Promises in javascript enable asynchronous handling of multiple tasks, such as making coffee and breakfast, and using promise.all to wait for both tasks to be done before proceeding.', 'duration': 28.392, 'max_score': 150.498, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo150498.jpg'}, {'end': 279.815, 'src': 'heatmap', 'start': 255.855, 'weight': 0.78, 'content': [{'end': 263.963, 'text': "So in this case, after 500 milliseconds, we're gonna resolve it with some data, or if it's less than 300 milliseconds, I'm gonna reject it,", 'start': 255.855, 'duration': 8.108}, {'end': 265.045, 'text': "because that's too fast.", 'start': 263.963, 'duration': 1.082}, {'end': 272.791, 'text': 'And what that will allow us to do is a little bit something like this, where we can write our code And then we can chain then, then, then on it.', 'start': 265.405, 'duration': 7.386}, {'end': 279.815, 'text': "And by returning a new promise from each one, we're allowed to keep going and chaining that code along the way.", 'start': 273.051, 'duration': 6.764}], 'summary': 'Resolve after 500ms, reject if less than 300ms, allows chaining code with promises.', 'duration': 23.96, 'max_score': 255.855, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo255855.jpg'}, {'end': 341.247, 'src': 'embed', 'start': 312.882, 'weight': 1, 'content': [{'end': 316.865, 'text': 'So we looked at this example earlier where we went from callback to promise base.', 'start': 312.882, 'duration': 3.983}, {'end': 324.31, 'text': 'Well, what we can do now, if you look at the bottom here, is we can simply make a function by tagging with a sync and then inside of that,', 'start': 317.145, 'duration': 7.165}, {'end': 331.234, 'text': 'we simply put the await keyword in front of each of those functions, and that will simply sort of pause the function from running.', 'start': 324.31, 'duration': 6.924}, {'end': 336.638, 'text': 'It will wait until that promise resolves, until it moves on to the next line of code.', 'start': 331.294, 'duration': 5.344}, {'end': 338.86, 'text': 'No thens, no callbacks needed.', 'start': 337.018, 'duration': 1.842}, {'end': 341.247, 'text': "So let's break it down.", 'start': 339.986, 'duration': 1.261}], 'summary': 'Using async/await simplifies handling promises, eliminating the need for callbacks.', 'duration': 28.365, 'max_score': 312.882, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo312882.jpg'}, {'end': 408.992, 'src': 'heatmap', 'start': 379.356, 'weight': 0.907, 'content': [{'end': 386.56, 'text': 'In JavaScript, what we can do is we can put both of those promises into variables and then wait until both of them come back.', 'start': 379.356, 'duration': 7.204}, {'end': 391.223, 'text': 'they can both fire off one after another and then we can wait for both of them to come back.', 'start': 386.56, 'duration': 4.663}, {'end': 395.907, 'text': 'and then we can use the data by creating some HTML and displaying it on the page.', 'start': 391.223, 'duration': 4.684}, {'end': 406.311, 'text': "So the PHP is kind of easier to read, but the JavaScript is more performant because we're not waiting on unnecessary things to finish.", 'start': 396.687, 'duration': 9.624}, {'end': 408.992, 'text': "But I'm not really happy with either.", 'start': 406.911, 'duration': 2.081}], 'summary': 'In javascript, we can wait for both promises to return before using the data, improving performance.', 'duration': 29.636, 'max_score': 379.356, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo379356.jpg'}, {'end': 499.985, 'src': 'heatmap', 'start': 473.134, 'weight': 0.718, 'content': [{'end': 481.099, 'text': 'What we can do is we can simply await promise.all and by passing promise.all our other two promises,', 'start': 473.134, 'duration': 7.965}, {'end': 485.482, 'text': 'we sort of make one big mega promise that we can await for both of them to finish.', 'start': 481.099, 'duration': 4.383}, {'end': 488.084, 'text': 'So one takes one second, one takes two seconds.', 'start': 485.522, 'duration': 2.562}, {'end': 491.666, 'text': "It's gonna wait the full two seconds before we go on to the next line of code.", 'start': 488.284, 'duration': 3.382}, {'end': 499.985, 'text': "Now, that's great, but if you've ever seen any examples online, the error handling starts to ugly it up.", 'start': 493.137, 'duration': 6.848}], 'summary': 'Using promise.all to combine two promises, one taking 1 second and the other taking 2 seconds, to await both to finish before proceeding.', 'duration': 26.851, 'max_score': 473.134, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo473134.jpg'}, {'end': 563.929, 'src': 'embed', 'start': 536.127, 'weight': 2, 'content': [{'end': 542.049, 'text': 'if anything happens inside of that try, you catch the error in your catch and you deal with it accordingly.', 'start': 536.127, 'duration': 5.922}, {'end': 552.706, 'text': 'Second or third option is a higher order function, which is kind of cool because you can chain a dot catch on async functions.', 'start': 543.624, 'duration': 9.082}, {'end': 554.907, 'text': 'So this is a little bit more complicated.', 'start': 553.227, 'duration': 1.68}, {'end': 558.888, 'text': "You might have to come back to these slides and look at it, but let's walk through an example.", 'start': 554.927, 'duration': 3.961}, {'end': 563.929, 'text': "So I've got a function, YOLO, where I don't care about error handling in this function.", 'start': 558.948, 'duration': 4.981}], 'summary': 'Handling errors in async functions using higher order functions, yolo function example.', 'duration': 27.802, 'max_score': 536.127, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo536127.jpg'}], 'start': 135.331, 'title': 'Promises and error handling', 'summary': 'Delves into handling asynchronous functions through promise chains, promise.all, and async await in javascript, and also explores error handling using try-catch and higher order functions.', 'chapters': [{'end': 581.59, 'start': 135.331, 'title': 'Promises, async await, and error handling', 'summary': 'Explains how promises allow asynchronous functions to be handled in a more readable and organized manner, demonstrating the use of promise chains, promise.all, and async await in javascript, while also discussing error handling through try-catch and higher order functions.', 'duration': 446.259, 'highlights': ['Promises and Asynchronous Functions Promises allow functions to return promises that data will come at some point in time, with the ability to use .then to listen for the data actually coming back, and promise.all enabling the waiting for multiple asynchronous tasks to be completed before moving forward.', 'Async Await Syntax The async await syntax provides a more synchronous-looking code without the downsides of writing synchronous code, where functions marked as async can utilize the await keyword to pause the function until a promise resolves and store the resolved data in a variable.', 'Error Handling Options Error handling options include using try-catch to wrap the code and catch any errors, or implementing higher order functions to chain a dot catch on async functions for more complex error handling scenarios.']}], 'duration': 446.259, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo135331.jpg', 'highlights': ['Promises and Asynchronous Functions Promises allow functions to return promises that data will come at some point in time, with the ability to use .then to listen for the data actually coming back, and promise.all enabling the waiting for multiple asynchronous tasks to be completed before moving forward.', 'Async Await Syntax The async await syntax provides a more synchronous-looking code without the downsides of writing synchronous code, where functions marked as async can utilize the await keyword to pause the function until a promise resolves and store the resolved data in a variable.', 'Error Handling Options Error handling options include using try-catch to wrap the code and catch any errors, or implementing higher order functions to chain a dot catch on async functions for more complex error handling scenarios.']}, {'end': 937.532, 'segs': [{'end': 602.639, 'src': 'embed', 'start': 581.59, 'weight': 0, 'content': [{'end': 591.914, 'text': 'you create a high-order function called handleError that takes as an argument the actual function, and then from that you return a new function.', 'start': 581.59, 'duration': 10.324}, {'end': 599.577, 'text': "so you basically just return the same function, but with a catch tagged onto the end, and the catch that's tagged onto the end.", 'start': 591.914, 'duration': 7.663}, {'end': 602.639, 'text': "that's where you actually handle your error.", 'start': 599.577, 'duration': 3.062}], 'summary': 'Create a high-order function, handleerror, that adds error handling to a function.', 'duration': 21.049, 'max_score': 581.59, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo581590.jpg'}, {'end': 610.777, 'src': 'heatmap', 'start': 581.59, 'weight': 1, 'content': [{'end': 591.914, 'text': 'you create a high-order function called handleError that takes as an argument the actual function, and then from that you return a new function.', 'start': 581.59, 'duration': 10.324}, {'end': 599.577, 'text': "so you basically just return the same function, but with a catch tagged onto the end, and the catch that's tagged onto the end.", 'start': 591.914, 'duration': 7.663}, {'end': 602.639, 'text': "that's where you actually handle your error.", 'start': 599.577, 'duration': 3.062}, {'end': 610.777, 'text': "If you're a hotshot and you're using ES6 for absolutely everything, you can do it in one line and then tweet about how cool you are.", 'start': 604.152, 'duration': 6.625}], 'summary': 'Create a high-order function to handle errors in es6, can be done in one line.', 'duration': 29.187, 'max_score': 581.59, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo581590.jpg'}, {'end': 717.293, 'src': 'embed', 'start': 695.298, 'weight': 1, 'content': [{'end': 704.005, 'text': "It doesn't handle unexpected errors or syntax errors or database connection errors or anything else that has happened along the line of your middleware.", 'start': 695.298, 'duration': 8.707}, {'end': 711.429, 'text': 'So what we need to do here is we need to catch all of our errors and pass them along to the next function.', 'start': 704.705, 'duration': 6.724}, {'end': 714.852, 'text': 'We want to pass any error and pass it along to the next function.', 'start': 711.469, 'duration': 3.383}, {'end': 717.293, 'text': 'So this is where our high order function comes in.', 'start': 715.372, 'duration': 1.921}], 'summary': 'Handling errors in middleware is crucial; passing them to the next function is key.', 'duration': 21.995, 'max_score': 695.298, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo695298.jpg'}, {'end': 770.744, 'src': 'embed', 'start': 741.389, 'weight': 2, 'content': [{'end': 742.91, 'text': 'You can do an arrow function.', 'start': 741.389, 'duration': 1.521}, {'end': 744.791, 'text': 'Now, this is how we implement it.', 'start': 743.391, 'duration': 1.4}, {'end': 746.092, 'text': "We've got our catch errors function.", 'start': 744.852, 'duration': 1.24}, {'end': 751.476, 'text': 'Then we write all of our routes or all of our controller functions without any error handling in it.', 'start': 746.493, 'duration': 4.983}, {'end': 757.518, 'text': 'And then you can take your controller get orders and pass it to catch errors.', 'start': 751.956, 'duration': 5.562}, {'end': 759.179, 'text': "And that's really really nice,", 'start': 757.638, 'duration': 1.541}, {'end': 766.502, 'text': 'because you can write all of your routes without having to worry about specifically handling the error in the exact same way.', 'start': 759.179, 'duration': 7.323}, {'end': 770.744, 'text': 'And then you can just wrap each of your routes in this catch errors function.', 'start': 766.922, 'duration': 3.822}], 'summary': 'Implement arrow function for error handling in routes and controller functions.', 'duration': 29.355, 'max_score': 741.389, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo741389.jpg'}, {'end': 828.329, 'src': 'embed', 'start': 781.781, 'weight': 3, 'content': [{'end': 784.522, 'text': "If there's an error here, I need to handle it in a different way.", 'start': 781.781, 'duration': 2.741}, {'end': 786.584, 'text': "So it's pretty simple.", 'start': 785.003, 'duration': 1.581}, {'end': 790.206, 'text': 'You make your async function called loadData and maybe an error happens in that.', 'start': 786.644, 'duration': 3.562}, {'end': 797.871, 'text': "When you call it, you can just chain a .catch onto the end and then deal with the error however it is that you'd like to do that.", 'start': 790.546, 'duration': 7.325}, {'end': 802.299, 'text': "Fifth option, and this is really important if you're writing Node.", 'start': 799.898, 'duration': 2.401}, {'end': 813.942, 'text': "Node will soon exit the process if your promise is rejected, meaning that if you have any code that doesn't handle an error on a promise,", 'start': 803.139, 'duration': 10.803}, {'end': 817.943, 'text': 'the entire process will exit, and then that could mean your app actually goes down.', 'start': 813.942, 'duration': 4.001}, {'end': 819.704, 'text': 'So pretty simple.', 'start': 818.543, 'duration': 1.161}, {'end': 828.329, 'text': 'You just listen for the unhandled rejection And then, when that happens, you can deal with it accordingly,', 'start': 819.764, 'duration': 8.565}], 'summary': 'Handling errors in async functions is crucial, especially in node, where unhandled rejections can cause the entire process to exit and potentially lead to app downtime.', 'duration': 46.548, 'max_score': 781.781, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo781781.jpg'}], 'start': 581.59, 'title': 'Error handling in javascript functions and async await best practices', 'summary': 'Covers the creation of handleerror high-order function for error handling in functions, focusing on catching and passing along various errors in javascript. it also discusses best practices for error handling in async await functions, including specific techniques and prevention of app shutdown in node.', 'chapters': [{'end': 741.329, 'start': 581.59, 'title': 'Handling errors in javascript functions', 'summary': 'Discusses the creation of a high-order function called handleerror to add error handling to functions, particularly in node and express, with a focus on catching and passing along any type of errors, such as unexpected errors or syntax errors, in javascript. it emphasizes the use of high-order functions to create new functions that are safer and can handle errors, providing specific examples of error handling in node and express.', 'duration': 159.739, 'highlights': ['The chapter explains the creation of a high-order function, handleError, to add error handling to functions in JavaScript, particularly in Node and Express, enabling the creation of safer functions that can handle various types of errors.', 'It emphasizes the importance of catching and passing along any type of errors, such as unexpected errors or syntax errors, in JavaScript, particularly in the context of middleware in Express applications.', 'The transcript provides a specific example of error handling in Express, highlighting the need to catch all errors and pass them along to the next function, particularly for unexpected errors, syntax errors, or database connection errors.']}, {'end': 937.532, 'start': 741.389, 'title': 'Async await best practices', 'summary': 'Discusses best practices for handling errors in async await functions, including using catch errors function to handle errors in controller functions, chaining .catch onto async functions for specific error handling, listening for unhandled rejections in node to prevent app shutdown, and utilizing async await for flow control and error handling.', 'duration': 196.143, 'highlights': ['The chapter emphasizes using the catch errors function to handle errors in controller functions, providing a seamless way to write routes without explicitly handling errors (e.g., get orders function).', 'The importance of handling errors in async functions is highlighted, suggesting chaining .catch onto async functions for specific error handling, allowing for different error treatment based on special cases.', "Node's behavior of exiting the process on unhandled promise rejections is explained, emphasizing the significance of listening for unhandled rejections to prevent app shutdown and implementing error handling services.", 'The benefits of using async await for flow control and error handling are discussed, showcasing its impact on JavaScript coding practices and recommending the adoption of async await for new APIs and the conversion of older APIs with promiseify.']}], 'duration': 355.942, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/DwQJ_NPQWWo/pics/DwQJ_NPQWWo581590.jpg', 'highlights': ['The chapter explains the creation of a high-order function, handleError, to add error handling to functions in JavaScript, particularly in Node and Express, enabling the creation of safer functions that can handle various types of errors.', 'The importance of catching and passing along any type of errors, such as unexpected errors or syntax errors, in JavaScript, particularly in the context of middleware in Express applications.', 'The chapter emphasizes using the catch errors function to handle errors in controller functions, providing a seamless way to write routes without explicitly handling errors (e.g., get orders function).', 'The importance of handling errors in async functions is highlighted, suggesting chaining .catch onto async functions for specific error handling, allowing for different error treatment based on special cases.', "Node's behavior of exiting the process on unhandled promise rejections is explained, emphasizing the significance of listening for unhandled rejections to prevent app shutdown and implementing error handling services."]}], 'highlights': ['Promises in JavaScript are foundational to async await, serving as an IOU for future events.', "JavaScript's asynchronous nature emphasizes the need to kick off processes and handle results, akin to real-life activities.", 'Promises and Asynchronous Functions Promises allow functions to return promises that data will come at some point in time, with the ability to use .then to listen for the data actually coming back, and promise.all enabling the waiting for multiple asynchronous tasks to be completed before moving forward.', 'Async Await Syntax The async await syntax provides a more synchronous-looking code without the downsides of writing synchronous code, where functions marked as async can utilize the await keyword to pause the function until a promise resolves and store the resolved data in a variable.', 'The chapter explains the creation of a high-order function, handleError, to add error handling to functions in JavaScript, particularly in Node and Express, enabling the creation of safer functions that can handle various types of errors.', 'The importance of catching and passing along any type of errors, such as unexpected errors or syntax errors, in JavaScript, particularly in the context of middleware in Express applications.', 'The importance of handling errors in async functions is highlighted, suggesting chaining .catch onto async functions for specific error handling, allowing for different error treatment based on special cases.', "Node's behavior of exiting the process on unhandled promise rejections is explained, emphasizing the significance of listening for unhandled rejections to prevent app shutdown and implementing error handling services."]}