You are really capable of making complex things much simpler, the way you describe is awesome, definitely you resolved your promise to make best video ever on promise :)
I promise to get my first JS job from Karl's training. If my dream resolved, then I will get a good pay and decent life, if the boss reject me, I will catch up, try another company or practice more.
Sorry for my nooby question, i am more python guy, just starting my journey into js. But i didn't get what for you need "promises"? Why you just don't use "if statement"?
When you're self taught your knowledge is all around the place, like you know classes, instantiation, scope, ES6, and a bunch of advanced stuff but don't know basic stuff like git. I'm in the middle of a very async heavy project on Express and was having a hard time with promises. I decided to take the WHOLE day off to look into it and it only took me 11 minutes thanks to this video. Now I can go back to my project with an extra day on my deadline. Thanks man, that was awesome!
"When you're self taught your knowledge is all around the place". Yeah, that's where I am with a lot of coding. I've been using 'async... await' and 'fetch' without really understanding the underlying 'Promise' object. Makes a lot more sense now!
How do you speak so flawlessly without pauses or ticks, all while typing out code with very few mistakes? Was this all one take? This shouldn't be possible
After watching crashcourses, long, 45 min videos and articles about promises, I can say this is probably the only video that actually made me understand promises. Wonderfully explained! Thank you so much, you have a new subscriber :) And also... The amount of dislikes says it all.
I’ve commented before, basically the same thing, but I REALLY enjoy your style of teaching. To the point, understandable examples, and clean code. This is by far the best video on Promises I’ve seen yet. Thank you!
Dude.... that was a CLEAN tutorial. I can easily go back and watch it a few times to practice it. Writing a promise to console log 1,2 and 3, in order, asynchronously , was an interview question. I watched your video to re-learn the syntax. Thanks!
Also the .then can take two functions as arguments. The first one being done on resolve and the second one for reject. .catch is the same thing as .then(null, reject)
.catch is not exaclty the same, becasue you can use different a "reject" for every .then, and use a common .catch at the end of the chain to catch any unhandled error.
I've been binge watching your videos and they are wonderful. Not too long and not too short while delivering the content clearly. Keep up the good work!!
I started learning development with udemy courses. It all went great and I've been through 2 interviews so far. In one of the interviews they told me to learn the theory behind promises and it turned out that I've used it many times but that video really helped me solidify the knowledge and understand the actual logic behind them. I always seek your short and straight-to-the point tutorials for similar cases. Thank you.
Great explanation of promises, Kyle! Using Promise.all and Promise.race really helps in managing multiple asynchronous operations efficiently. For those looking to write cleaner and more maintainable code, promises are a game-changer compared to traditional callbacks. Thanks for breaking it down so clearly!
The promise code for the first example gave me a “Promise {}” when a = 2. It gave me the correct result when a = 3. Ran straight and with localhost. Both were the same, thoughts?
It sounds like your promise is never calling resolve or reject. You might want to check to make sure that your if logic is correctly setup so that either resolve or reject are always called inside your promise.
Promise has three states which are; 1. Pending, 2. fulfilled and 3. reject. when you defined a promise in a function, that function remains in a pending state untill you run the code and now result in a certain condition base on your logic, that is when the function will enter into being fulfilled or rejected.
Done thanks Promise is itself declared as new Promise((resolve, reject) => {//promise logic here}), takes a function as parameter, that function takes two functions/callbacks resolve and reject. The logic of the promise itself is defined in the callback that the promise was initialized with, which calls the resolve or reject callback. The caller of the promise can call .then(theParamResolveGot => { //the resolve logic}) passing it a callback which takes the same parameter that is passed to the resolve callback inside the Promise. Calling .catch(theParamRejectGot => {//logic to handle rejected promise}) Can then chain callback after callback by chaining .then which avoids callback hell
Just learned about callbacks. Then I realized there is a better way called Promises. Now that I learned promises, I realized there is syntactic sugar for promise.then().catch() called async/await. Learning programming is a rabbit hole!
question, can the 'message' can be change to any other word, or 'message' is a function? I'm doing a course, and it's using 'result' instead of your example 'message'. Thank you.
Just a reminder that Callback Hell IS a real place where you WILL be sent at the first missing curly brace. In all seriousness though, great walkthrough!
I really went down the rabbit hole with this one... Was initially learning about CPU hyperthreading and got confused between concurrency, parallelism, and sync and async tasks. Learning that introduced me to asynchronous code, which finally led me here. I don't even know JS lol. Really good video! I found this quite interesting.
Yeah. This is the best video from my Async JS marathon. Superb, right-to-the-point and practical explanations. You did, pal. One more subscriber. Keep up the good work!
Fantastic explanation! My only feedback is to increase the font size in your editor for those of us watching on mobile (and I'm sure desktop would benefit) when doing these smaller examples. Would be a lot easier to read.
Do you have a tutorial for fetching a json from an api with a promise? i am getting so confused and i don't even understand why. I will try it again now that i watched this video. Anyway if you have a specific video on fetch and promise let me know
I watched 4-5 other videos about callbacks, promises before watching this video, was not satisfied. I am very much satisfied with your explanation in just 10 mins. Great 👍
Thank you! I try to make all my videos as concise and informational as possible. My goal is the be the channel with the most learning per minute of content.
This is amazing! Thank you so much 😊. You explained this perfectly. I have been trying to learn this for weeks and I’ve been failing but I just learned it in 10 minutes! I completely understand this now, thank you! YOU HAVE A NEW SUBSCRIBER 😄😄
Awesome! I have been struggling with this subject for a whole week. I read every resource I could find on the internet. This video finally made me understand promises in a matter of 5 minutes.
@@WebDevSimplified While I like it, I consider it a bad practise whether it's allowed or not. But I find JS rather messed up anyway. -- Don't attack me on it though, I use it when needed (Which is currently using NodeJS + Electron).
Thank you so much for your videos! You have a great talent for teaching :D I wish college teachers were like this, mine would only read their PPT in class :(
Why do all coding tutorials have these comments like 'super simple explanantion' "best video ever" ...no matter how bad the explanation was. It will always be a mystery to me
Ok. Two things: 1) slow down about 2-3x. 2). As someone that is being forced to take JavaScrip for a CS major, I can't help but notice how terribly JavaScrip is compared to other programming languages... literally feels like a house made of scraps ... there just isn't any clear consistency or common sense built into this language ... it's all just a bunch of strung together libraries and weird syntax that was build over whatever was there before ... everything seems to be based on word of mouth and experience rather than the structured and consistent approach used by other programming languages. I thought Python was terrible, but JavaScrip takes it to the next level of confusion. Somehow the claim is that this makes things faster and easier, but all I see is a bunch of unnecessary complexity that could be simplified by going back to the basics.
Dude Javascript is a language that was built for browsers initially.Today the many versions of JS introduced new syntax which is confusing but there is a reason behind the weird things of JS. Its cause of 2 things they are doing at the same time, one is they don't want to break the code written a long time ago another is they are making development easy for the devs by implementing new features and syntaxes..Javascript should have a backward compatibility always.
I do no know how to say it - as some months ago you payed attention to my question and responded very promptly. I am very thankful for that. I saw other sources saying that Catch is not for catching Reject state, although it works there too. Catch should be for catching an unexpected error. Rather Then has (or can have) two functions as parameters - first one for Resolve, the second for Reject. Could you elaborate on that I hope I am bringing a constructive question.
This tutorial was like revisiting form basics to learn to pro. I read some articles about Promises and I sort of knew what this was about. But the way he gave the example, this just got stuck in my mind. thanks man
Probably the best video on RUclips that explains promises in such a lucid fashion. Liked, commented, subscribed and shared as well. Keep up the good work man.
For those of you being confused about the syntax, just ignore the passing of "resolve, reject" into the promise callback as parameters. Long story short, JS engines could have done just fine without requiring the explicit passing of these two parameters as they serve literally no practical purpose ever. Don't know why they made the syntax like this, but yea ignore these two parameters from your mental model, and all of a sudden, the syntax will look like any standard JS API syntax.
You have fulfilled the promise of conveying the tutorial of "Promises" in a very promising manner. I have liked, comment and subscribed :D
4 года назад
FYI I get this msg when I typed the program as at 3:54: (node:10099) UnhandledPromiseRejectionWarning: ReferenceError: Cannot access 'p' before initialization at /home/kemal/WDS/promise.js:11:1 at new Promise () at Object. (/home/kemal/WDS/promise.js:1:9) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47 (node:10099) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:10099) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
At 10:17 you discuss that promise.all() runs all three promises at the same time but when I try the following it still lists the output in the order that the promises are listed even though promis1 takes 5 seconds while the other two finish almost instantly: --- const promise1 = new Promise((resolve, reject) => { setTimeout(resolve, 5000, 'foo'); }); const promise2 = Promise.resolve(3); const promise3 = 42; Promise.all([promise1, promise2, promise3]).then((values) => { console.log(values); }); // output: Array ["foo", 3, 42"] ---
Hi! can you do a video of a promise all but WITH async/await pls like let arrayofData = [infoA, infoB, infoC] Promise.all(arrayofData.map(async(data,i)=>{ let res = await someRandomApiCallWithDifferentDelayTimes() return res }))
why do you use "catch()"? Cant you just do" p.then((message) => {console.log(" " + message)}), (message) => {console.log(" " + message)});? Or do you need to have a print function instead of console.log to do that?
If you enjoy promises make sure to checkout Async/Await.
ruclips.net/video/V_Kr9OSfDeU/видео.html
Did something go wrong with the video upload? I'm seeing your VS Code video instead of your JScript promises video
It sounds like a problem with RUclips. That has happened to me before. Just try refreshing the page. That usually fixes it for me.
Can you create a video on firebase cloud functions
I have never used firebase so I am not sure if I will cover it anytime soon
is promise doesn't need to be declared first?
watchThisVideo.then(() => celebrate()).catch(() => sadness())
watchedTheVideo.then((data)=>{ }).catch((error)=>{ console.log("error: ", error) }); ..................... CONSOLE - error: "PERFECT PROMISE VIDEO FOR BEGINNERS"
@Đeath Vader lol
@@garrybogdanhoshame
The first promise video that actually helped
thanks man. you really hit the nail on the head, would be cool if you had an online course on one of these platforms. thanks
You are really capable of making complex things much simpler, the way you describe is awesome, definitely you resolved your promise to make best video ever on promise :)
Very good, as always!
Greetings from Brazil.
Your videos are just like call stack. I started from the async wait video. Then here. Now I have to to go to another video.
I tried to cover a ton of different linked concepts in small digestible videos to make it easier to follow them all.
I promise to get my first JS job from Karl's training. If my dream resolved, then I will get a good pay and decent life, if the boss reject me, I will catch up, try another company or practice more.
Thank you for your video, but I didn't quite understand if promises are asynchronous or synchronous. Could also explain me why?
This is the best video ❤️❤️
Thanks man, you helped me a lot.
Me: How the F do I use an API?
WebDevSimplified: Take my hand.
Video: JavaScript promises in 10 mins.
Me: Checks video length - 11 min
Also me: I guess promises are meant to be broken..
Your promise has been resolved !
"I promise to make the best video on promises I can."
I like this guy.
"I promise to make a video on promises the best that I can" or "I promise to make , as best as i can , a video on promise " FTFY
Reject his promise. I am kidding :)
Resolved..:)
00:24
He should've shown a sample of a minimum time consuming URL visit, not simple artithmetic 1 + 1. I don't like this tutotial. ~04:37
You resolve your promise, you make me fully understand
I'm glad I could help
Sorry for my nooby question, i am more python guy, just starting my journey into js. But i didn't get what for you need "promises"? Why you just don't use "if statement"?
@@joma0305 watch the video one more time then because he explained it multiple times
@@Al_Gonzo i did ut before your comment. If you so smart pls explain
@@Al_Gonzo or it's just a "sugar" of js pl
When you're self taught your knowledge is all around the place, like you know classes, instantiation, scope, ES6, and a bunch of advanced stuff but don't know basic stuff like git. I'm in the middle of a very async heavy project on Express and was having a hard time with promises. I decided to take the WHOLE day off to look into it and it only took me 11 minutes thanks to this video. Now I can go back to my project with an extra day on my deadline. Thanks man, that was awesome!
"When you're self taught your knowledge is all around the place". Yeah, that's where I am with a lot of coding. I've been using 'async... await' and 'fetch' without really understanding the underlying 'Promise' object. Makes a lot more sense now!
express can do async now lol nice. i since moved on to koa but i use express for future devs that aren't me.
@@notdaveschannel9843 async await is just syntatic sugar, you need to know promises instead
This is such a factual comment. Ive made 3d games with javascript that run in the browser, yet here I am, finally learning how promises work😂
How do you speak so flawlessly without pauses or ticks, all while typing out code with very few mistakes? Was this all one take? This shouldn't be possible
Smart people talk like this.
After watching crashcourses, long, 45 min videos and articles about promises, I can say this is probably the only video that actually made me understand promises. Wonderfully explained! Thank you so much, you have a new subscriber :)
And also... The amount of dislikes says it all.
Thank you! I am really glad I could help.
You took the same path as myself. I have been taking a marathon of Async Javascript to grasp on for once and for all.
same here
Even the official documentation by MDN sucked!!
@@animeshsharma7332 true that!
I’ve commented before, basically the same thing, but I REALLY enjoy your style of teaching. To the point, understandable examples, and clean code. This is by far the best video on Promises I’ve seen yet. Thank you!
Thank you so much!
Dude.... that was a CLEAN tutorial. I can easily go back and watch it a few times to practice it. Writing a promise to console log 1,2 and 3, in order, asynchronously , was an interview question. I watched your video to re-learn the syntax. Thanks!
I'm really glad the video was able to help!
hey man did you get the job?
@@divinemasculine3730 not only did I get that job. I have just recently accepted an offer from the company behind this very platform 😉.
@@jamesonvparker wow youtube??? so inpirational! can you give me tips? im from canada going through a FULL STACK coding bootcamp
@@divinemasculine3730 find me on linked in. I’ll talk there
Wow, this made much more sense than the udemy course I'm taking right now.
Also the .then can take two functions as arguments. The first one being done on resolve and the second one for reject. .catch is the same thing as .then(null, reject)
.catch is not exaclty the same, becasue you can use different a "reject" for every .then, and use a common .catch at the end of the chain to catch any unhandled error.
This is so confusing to understand
The last 11 minutes and 30 seconds of my life was well spent.
Great upload!
Thank you so much! I'm glad you enjoyed it.
are you dead ?
RIP
rest in rip
The guy liked this 11:31 long video so much that his profile picture is now his new favorite numbers, "3" and "1".
new Promise((resolve,reject)=>{
let a = 1
if(a==1){resolve("you taught me well")}
})
I am a very young programmer and Kyle will always be my favorite programming RUclipsr out there.
Guess my age
I've been binge watching your videos and they are wonderful. Not too long and not too short while delivering the content clearly. Keep up the good work!!
Bro, been trying to understand this for an hour. Your video was the first where it all clicked. Thanks!
You definitely kept your promise about the video. Good work!
Thanks! I'm glad you enjoyed it
This channel is massively underrated 🙌🏻
Thanks! I think 4,000 is a pretty huge number already, but I am excited to see what the future holds.
See this is what I was talking about!!! Way to go buddy!!!
@@udeleted almost doubled 3 months later. Race for a million. I’m a new sub
I started learning development with udemy courses. It all went great and I've been through 2 interviews so far.
In one of the interviews they told me to learn the theory behind promises and it turned out that I've used it many times but that video really helped me solidify the knowledge and understand the actual logic behind them.
I always seek your short and straight-to-the point tutorials for similar cases.
Thank you.
thanks for simplifying promises concept, this is a great video for sure.
"...and that cats are better than me"
🤣
Thanks for your help
You're welcome! I'm glad I could help.
Great explanation of promises, Kyle! Using Promise.all and Promise.race really helps in managing multiple asynchronous operations efficiently. For those looking to write cleaner and more maintainable code, promises are a game-changer compared to traditional callbacks. Thanks for breaking it down so clearly!
The promise code for the first example gave me a “Promise {}” when a = 2. It gave me the correct result when a = 3. Ran straight and with localhost. Both were the same, thoughts?
It sounds like your promise is never calling resolve or reject. You might want to check to make sure that your if logic is correctly setup so that either resolve or reject are always called inside your promise.
Promise has three states which are; 1. Pending, 2. fulfilled and 3. reject. when you defined a promise in a function, that function remains in a pending state untill you run the code and now result in a certain condition base on your logic, that is when the function will enter into being fulfilled or rejected.
you can try "Promise(**).then(**).then(**)". Means try to see in second "then"
Done thanks
Promise is itself declared as new Promise((resolve, reject) => {//promise logic here}), takes a function as parameter, that function takes two functions/callbacks resolve and reject.
The logic of the promise itself is defined in the callback that the promise was initialized with, which calls the resolve or reject callback.
The caller of the promise can call .then(theParamResolveGot => {
//the resolve logic}) passing it a callback which takes the same parameter that is passed to the resolve callback inside the Promise.
Calling .catch(theParamRejectGot => {//logic to handle rejected promise})
Can then chain callback after callback by chaining .then which avoids callback hell
I am learning a lot from you . Your videos are always to the point . As a self taught programmer, this channel is a gem . Thank you so much : )
So how did your self taught programmer journey go? Asking for a friend 😂
Just learned about callbacks. Then I realized there is a better way called Promises. Now that I learned promises, I realized there is syntactic sugar for promise.then().catch() called async/await.
Learning programming is a rabbit hole!
Dude, your tutorials are amazing. Thanks for everything you teach us. Greetings from Costa Rica
Thank you! It always amazes me how many people from all over the world have seen one of my videos.
Thank You So Much for this wonderfull video................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
So like
then ==> runs for resolve
and
catch ===> runs for reject
question, can the 'message' can be change to any other word, or 'message' is a function? I'm doing a course, and it's using 'result' instead of your example 'message'. Thank you.
I read the entire MDN section on Promises and 11 mins convert me into a promise pro thank you sir
Just a reminder that Callback Hell IS a real place where you WILL be sent at the first missing curly brace.
In all seriousness though, great walkthrough!
Dislikers thinking that button is for download this 😂
😂
We have an expression in the Hindi language for the way you explained the things here: "Kya Baat Hai!" (which mean "How brilliant!")
I really went down the rabbit hole with this one... Was initially learning about CPU hyperthreading and got confused between concurrency, parallelism, and sync and async tasks. Learning that introduced me to asynchronous code, which finally led me here. I don't even know JS lol.
Really good video! I found this quite interesting.
Promised half fulfilled. It would have been nice to see some examples with asynchronous operations. The examples felt a bit contrived.
guy explained in 11 mins what took hours for my instructor. thank you 🙏
Istg, i am super happy now... I COULD FINALLY UNDERTAND PROMISES
Yeah. This is the best video from my Async JS marathon. Superb, right-to-the-point and practical explanations. You did, pal. One more subscriber. Keep up the good work!
This video within 3 minutes explained everything about promises.
Fantastic explanation! My only feedback is to increase the font size in your editor for those of us watching on mobile (and I'm sure desktop would benefit) when doing these smaller examples. Would be a lot easier to read.
Do you have a tutorial for fetching a json from an api with a promise? i am getting so confused and i don't even understand why. I will try it again now that i watched this video. Anyway if you have a specific video on fetch and promise let me know
I watched 4-5 other videos about callbacks, promises before watching this video, was not satisfied. I am very much satisfied with your explanation in just 10 mins. Great 👍
Thank you! I try to make all my videos as concise and informational as possible. My goal is the be the channel with the most learning per minute of content.
@@WebDevSimplified Yeah think we can all agree you're pulling that one off. Congrats on your engagement also, huge
Thanks bro it was really helpful I generally don't leave a comment but his channel is a hidden gem bro thank you❤
This is amazing! Thank you so much 😊. You explained this perfectly. I have been trying to learn this for weeks and I’ve been failing but I just learned it in 10 minutes! I completely understand this now, thank you! YOU HAVE A NEW SUBSCRIBER 😄😄
Thank you so much! I am really glad I could help, and I hope my other videos are just as helpful.
Web Dev Simplified thank you
I LOVE YOU KYLE! (no homo hahahaha)
THANK YOU SO MUCH MAN! YOU REALLY MADE IT VERY SIMPLE TO UNDERSTAND THIS TOPIC! 😍😂😘😘
Awesome!
I have been struggling with this subject for a whole week. I read every resource I could find on the internet. This video finally made me understand promises in a matter of 5 minutes.
That feeling as a Java developer to see statements ending without semi-colon...
It is a great feeling.
@@WebDevSimplified While I like it, I consider it a bad practise whether it's allowed or not.
But I find JS rather messed up anyway.
-- Don't attack me on it though, I use it when needed (Which is currently using NodeJS + Electron).
so we can execute the functions in parallel but how isnt Javascript is single threaded
Thank you so much for your videos! You have a great talent for teaching :D I wish college teachers were like this, mine would only read their PPT in class :(
Man, my only request is for you to speak faster, except that it's great.
I learned more about promises from this ten-minute video than I did from an entire fifteen week web dev course in school. Can't thank you enough!
I'm really glad I could help!
Web deb course in school? I could only dream about this. The only thing i've learnt from school is how to open ms word.
Why do all coding tutorials have these comments like 'super simple explanantion' "best video ever" ...no matter how bad the explanation was. It will always be a mystery to me
That really helped. Thanks from India.👍👍
Ok. Two things: 1) slow down about 2-3x. 2). As someone that is being forced to take JavaScrip for a CS major, I can't help but notice how terribly JavaScrip is compared to other programming languages... literally feels like a house made of scraps ... there just isn't any clear consistency or common sense built into this language ... it's all just a bunch of strung together libraries and weird syntax that was build over whatever was there before ... everything seems to be based on word of mouth and experience rather than the structured and consistent approach used by other programming languages. I thought Python was terrible, but JavaScrip takes it to the next level of confusion. Somehow the claim is that this makes things faster and easier, but all I see is a bunch of unnecessary complexity that could be simplified by going back to the basics.
You are so right about this!
Dude Javascript is a language that was built for browsers initially.Today the many versions of JS introduced new syntax which is confusing but there is a reason behind the weird things of JS. Its cause of 2 things they are doing at the same time, one is they don't want to break the code written a long time ago another is they are making development easy for the devs by implementing new features and syntaxes..Javascript should have a backward compatibility always.
Bro, what are you talking about? I had to put the video in 1.25x because it was too slow.
This was very helpful, thank you!
Not simple at all 😁
So...the Promise method is just an if/else statement?
Great Video ! Thank you so much :)
Alright, this is official now. I MugenSora, declare you the best out there.
What is the difference?
- use 2 callbacks in then: then(onfulfilled, onrejected)
- using only catch: catch(onrejected)
The result will be same but we use catch because of readability and clean code.
@@akashgupta1353 okay. Thanks for the reply.
I do no know how to say it - as some months ago you payed attention to my question and responded very promptly. I am very thankful for that.
I saw other sources saying that Catch is not for catching Reject state, although it works there too. Catch should be for catching an unexpected error. Rather Then has (or can have) two functions as parameters - first one for Resolve, the second for Reject.
Could you elaborate on that
I hope I am bringing a constructive question.
This tutorial was like revisiting form basics to learn to pro. I read some articles about Promises and I sort of knew what this was about. But the way he gave the example, this just got stuck in my mind. thanks man
thank you, simple and to the point :)
The best video on promises I came across !
I love you for this video. Wtf callback hell, go back to your prison!!!!
Awesome explanation, thanks
Finally I understand this, not afraid of promises anymore.
Always keep your promise guys.
You really simplified my javascript learning journey
thank you kyle, Hats off for you 🎩
Absolutely unclear topic 🤪
Omg your a life saver :) tysm
Your video is 5 years old, But I think it’s still the best.
it was a promise😂😂
So it's basically a try-catch-finally statement like in c#?
It's a re-callable try-catch. Promises give you the freedom to do anything you want when you call them in the then-catch callbacks
Probably the best video on RUclips that explains promises in such a lucid fashion. Liked, commented, subscribed and shared as well. Keep up the good work man.
Been stuck on learning Promises as a beginner and this has helped tremendously! Cheers!
Thks for existing my beloved teacher😍
For those of you being confused about the syntax, just ignore the passing of "resolve, reject" into the promise callback as parameters. Long story short, JS engines could have done just fine without requiring the explicit passing of these two parameters as they serve literally no practical purpose ever. Don't know why they made the syntax like this, but yea ignore these two parameters from your mental model, and all of a sudden, the syntax will look like any standard JS API syntax.
This is the most important video I have watched today so far
The parameters of the promise can be rename or it is default? Thanks
Can be
i fucking love you man god damnit
You have fulfilled the promise of conveying the tutorial of "Promises" in a very promising manner. I have liked, comment and subscribed :D
FYI I get this msg when I typed the program as at 3:54:
(node:10099) UnhandledPromiseRejectionWarning: ReferenceError: Cannot access 'p' before initialization
at /home/kemal/WDS/promise.js:11:1
at new Promise ()
at Object. (/home/kemal/WDS/promise.js:1:9)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
(node:10099) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10099) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
At 10:17 you discuss that promise.all() runs all three promises at the same time but when I try the following it still lists the output in the order that the promises are listed even though promis1 takes 5 seconds while the other two finish almost instantly:
---
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 5000, 'foo');
});
const promise2 = Promise.resolve(3);
const promise3 = 42;
Promise.all([promise1, promise2, promise3]).then((values) => {
console.log(values);
});
// output: Array ["foo", 3, 42"]
---
regarding async/await, this was also very helpful: tutorialedge.net/typescript/async-await-in-typescript-tutorial/
Hi! can you do a video of a promise all but WITH async/await pls like
let arrayofData = [infoA, infoB, infoC]
Promise.all(arrayofData.map(async(data,i)=>{
let res = await someRandomApiCallWithDifferentDelayTimes()
return res
}))
i deconstructed the callback fun used in this video this will avoid all the confusions
const userLeft = false;
const catMeme = false;
function watchTuts(call, error){
if(userLeft){
return error( obj1);
}else if(catMeme){
return error(obj2);
}else{
return call();
}
}
function callback(){
return 'thumbs up'
}
function errorCallback(object){
return ` ${object.name} ${object.message}`;
}
const obj1 = {
name: 'user left',
message: 'sad'
}
const obj2 = {
name: 'cat meme',
message: 'depressed'
}
console.log(watchTuts(callback, errorCallback));
why do you use "catch()"? Cant you just do" p.then((message) => {console.log(" " + message)}), (message) => {console.log(" " + message)});? Or do you need to have a print function instead of console.log to do that?