Asynchronous programming crash course in JavaScript | Callbacks, Promises & Async Await (in 13 min)
Asynchronous programming in JavaScript is an important concept that allow you to run your code in the background without blocking other code. We can use this to create an efficient and responsive application with the healp of callbacks, async/await, and promises.
Problem statement : When we have to execute some code that take some time to execute, JavaScript dont wait for that code to finish it execution like and API call, File or Database read and write operations etc. To solve this problem we can use Async programming in JavaScript. We have multiple ways to solve this problem statement.
1: Callbacks : A JavaScript callback is a function which is to be executed after another function has finished execution. A more formal definition would be - Any function that is passed as an argument to another function so that it can be executed in that other function is called as a callback function.
Problems with callbacks
a: Callback hell : Callback hell is a phenomenon that happens when multiple callbacks are nested on top of each other.
b: Inversion of control : Inversion of control is the notion of having code under your control in one part of the program, then handing control over to a callback in another part of the program.
2: Promises : The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
More about promises :
a: States of a promise : A promise has three states:
pending: the promise is still in the works.
fulfilled: the promise resolves successfully and returns a value.
rejected: the promise fails with an error.
b: Promise chaining : This solves the problem of callback hell. JavaScript promises can be chained together for using the settled promises (resolved or rejected), as well as the promises' values to control the flow of code.
3: Async/Await
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains.
In this video I have explained these conecpts in detail.
Topics explained in this video are one of the most common topics asked in JavaScript interview questions.
Cheers,
Sahil Ahlawat
https://freelancingdiary.com/
Would love to Stay Connected with you ❤️
LinkedIn - https://www.linkedin.com/in/sahil-ahlawat
Instagram - https://www.instagram.com/sahil_devil
#sahilahlawat #javascript #english #object #destructuring #objectdestructuring #javascriptsimplified #javascriptcrashcourse #crashcourse #callback #callbacks #callbakcfunction #callbackhell #inversionofcontrol #problemswithcallbacks #promises #async #await #asyncawait #reject #resolve #then #catch #finally #promisechaining #asynchronous #asyncjavascript #asynchronousjavascript
Видео Asynchronous programming crash course in JavaScript | Callbacks, Promises & Async Await (in 13 min) автора Библиотеки JavaScript
Видео Asynchronous programming crash course in JavaScript | Callbacks, Promises & Async Await (in 13 min) автора Библиотеки JavaScript
Информация
29 ноября 2023 г. 4:19:10
00:13:08
Похожие видео