JavaScript ASYNC/AWAIT is easy! ⏳

  Рет қаралды 43,721

Bro Code

Bro Code

5 ай бұрын

#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();

Пікірлер: 39
@BroCodez
@BroCodez 5 ай бұрын
// 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 2 ай бұрын
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?
@TheComputerSciencestudent.
@TheComputerSciencestudent. 5 ай бұрын
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 19 күн бұрын
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
@darrenharris5231
@darrenharris5231 4 ай бұрын
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 23 күн бұрын
short but perfect and easy to understand. Thanks for sharing good tips.
@metaobserver657
@metaobserver657 5 ай бұрын
THE best JS instructionals
@x..darkfate..x
@x..darkfate..x 6 күн бұрын
short and crisp video thnx for sharing
@rbsfinger
@rbsfinger 3 ай бұрын
Very helpful. Thanks for the video.
@abdosamir_225
@abdosamir_225 7 күн бұрын
you are brilliant man
@yuvarajsingh7806
@yuvarajsingh7806 Ай бұрын
Thankyou sir your teaching style is awesome❤
@manuelvaal1257
@manuelvaal1257 25 күн бұрын
Very much needed!❤
@reggiehurley1479
@reggiehurley1479 4 ай бұрын
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
@yohannestsegaye6945
@yohannestsegaye6945 2 ай бұрын
really helpful,Thank You sir
@robeeeeen
@robeeeeen 2 күн бұрын
This is much better than the last .then video and useful.
@footy895
@footy895 5 ай бұрын
Bro are you a full time youtuber or working for a company?,your coding skills are really good
@mzedan2
@mzedan2 2 ай бұрын
Thank you very much
@alexaldridge3454
@alexaldridge3454 Ай бұрын
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
@antcannon
@antcannon Ай бұрын
Is there a way to get the data from inside the async function saved to a variable for later use?
@ALLSTARDECOURO2
@ALLSTARDECOURO2 4 ай бұрын
good stuff
@gabrielzanda6890
@gabrielzanda6890 4 ай бұрын
Lov u bro
@axshat_in
@axshat_in 5 ай бұрын
Is Next Js Is the future?
@Taofetch
@Taofetch 5 ай бұрын
which tutorial playlist I should follow, this 2024 one or the older one?
@Taofetch
@Taofetch 5 ай бұрын
I`m one hour passed in the full 8 course vid and stuck between choosing what to follow now
@BroCodez
@BroCodez 5 ай бұрын
This playlist is the updated version
@Taofetch
@Taofetch 5 ай бұрын
@@BroCodezthankyou and have a great day bro!
@laperplayz1388
@laperplayz1388 5 ай бұрын
@@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
@BIRBHUMBOY-yy8ne
@BIRBHUMBOY-yy8ne 3 ай бұрын
Make a in depth asynchronous video
@alisanan9090
@alisanan9090 5 ай бұрын
catch (error) { throw(error); }
@hunin27
@hunin27 5 ай бұрын
i started learning node.js and im explding its too hard :((
@CoolestPossibleName
@CoolestPossibleName 5 ай бұрын
Go programming language is made by life much easier
@NAMEYOUTUBER
@NAMEYOUTUBER 5 ай бұрын
pls dont explde
@hunin27
@hunin27 5 ай бұрын
ill try. i start to learn a bit more@@NAMEKZbinR
@ALLSTARDECOURO2
@ALLSTARDECOURO2 4 ай бұрын
so did you learned it?
@hunin27
@hunin27 4 ай бұрын
@@ALLSTARDECOURO2 yes
Learn JSON files in 10 minutes! 📄
10:09
Bro Code
Рет қаралды 31 М.
How To Create Your Own Implementation Of JavaScript Promises
33:34
Web Dev Simplified
Рет қаралды 98 М.
Маленькая и средняя фанта
00:56
Multi DO Smile Russian
Рет қаралды 5 МЛН
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 71 МЛН
Normal vs Smokers !! 😱😱😱
00:12
Tibo InShape
Рет қаралды 118 МЛН
All The JavaScript You Need To Know For React
28:00
PedroTech
Рет қаралды 544 М.
What are JavaScript PROMISES? 🤞
12:37
Bro Code
Рет қаралды 35 М.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 79 М.
Async JavaScript & Callback Functions -- Tutorial for Beginners
24:21
Просто o async, await. Без циклов и таймеров. JavaScript
15:55
WebDev с нуля. Канал Алекса Лущенко
Рет қаралды 94 М.
Learn JavaScript ARROW FUNCTIONS in 8 minutes! 🎯
8:02
Bro Code
Рет қаралды 19 М.
Async JS Crash Course - Callbacks, Promises, Async Await
24:31
Traversy Media
Рет қаралды 1,4 МЛН
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
Маленькая и средняя фанта
00:56
Multi DO Smile Russian
Рет қаралды 5 МЛН