Bravo! Before I watched your video I was preconditioned that promise in Js is hard to grasp and understand. I got it after 20 min .. amazing content :)
At 23:28, what happens when there is an error in the second .then? Won't the following .then get executed? It seems like the control flow moves to .catch whenever an Error is created. Is it so? And .then before .catch doesn't returns a promise, how can it work at all?
Yes, if there is an error, it jumps to .catch and executes whatever is in .catch. So you need to make sure you include in .catch what you want to happen if there is an error. If you need to address errors individual, pass two functions to each .then.
Wonderful tutorial on promises. Where is the code of asyncFunction( ) ? I mean the body of asyncFunction( ). Your voice is clear and the way you explain with example code is too good. The best teacher on javascript award goes to you :-) .
Thanks for the positive feedback! The asyncFunction is in a separate JS file attached to the same HTML page. I just separated it to simulate a function that might not be a part of your own code.
I don't remember the exact function but it was simply doing a settimeout I believe. Something like this: let asyncFunction = function() { return new Promise(function(resolve, reject) { setTimeout(function() { resolve(asyncFunction has been resolved"); }, 5000) }); };
asyncFunction just returns a promise. That is all. It sets a short timer and then returns a promise. If you haven't yet it may help to watch all the movies in the playlist: ua-cam.com/play/PLTo9PCskHpbHIDnzl8tRYldSCSQaFgAHd.html
Thank you for explaining it well. But I just have one question, does the .then functions itself returns a promise? Because you chained the .catch function to the .then function.
Sir i am not able to understand ..a function that returns promise which converts the given array of string into uppercase and returns the result after n seconds, where n is the length of input array.
An array like object is simply an object that has a length property and then some indexed properties. So it has features of an Array, but was not created with the array literal ([]) or array constructor (new Array()). I'm not sure why you would want to create one, just create an array. However, sometimes these are created for you. For example, a node list (when you select HTML nodes) and the arguments of a function are array like. Usually we convert array like objects to arrays in order to work with them. Here is a tutorial: ua-cam.com/video/avPIXAftj24/v-deo.html
Great! One thing that I find odd is..where is the asyncFunction () and asyncFunction2 () declarations? BTW, I love all your tutorials, please keep up the good work!
@@anishkc1831 It just has a setTimeout is all. It looks something like this: let asyncFunction = function() { return new Promise(function(resolve, reject) { setTimeout(function() { resolve("asyncFunction has resolved."); }, 4000); }); };
Can not believe from all my classes it the course where i get the closest of understanding it but hahah still the logic escape me terrible hey lol I will get it :)
As a beginner I wouldn't suggest learning promises from the start. I would recommend starting with the basics first. Perhaps a book or a course to get the basics down and then you can add to it.
If you are interested in my getting started course let me know. I'm not trying to sell this to you, I just think you would avoid a lot of frustration by learning the basics first. Good Luck! Stick with it!
The concept is easy, the syntax is confusing !! in JavaScipt so many brackets etc..etc... and all tutorials assume you known the syntax frustrating !!!
@@vinayn9110 This is really considered a callback. I've got multiple tutorials on callbacks you may want to look at. This is a declared functions that is passed into another function; in this case the then method of a promise. The then method is then responsible for invoking that function. Callbacks can be a bit confusing, but are vary powerful. Here are links to a couple of tutorials: ua-cam.com/video/Nau-iEEgEoM/v-deo.html and ua-cam.com/video/tBjvWZn9fvs/v-deo.html
Thank you. It's a pleasure to watch such detailed and simplified for understanding materials. Thank you so much for your work.
Bravo! Before I watched your video I was preconditioned that promise in Js is hard to grasp and understand. I got it after 20 min .. amazing content :)
Glad it was helpful!
At 23:28, what happens when there is an error in the second .then?
Won't the following .then get executed?
It seems like the control flow moves to .catch whenever an Error is created. Is it so? And .then before .catch doesn't returns a promise, how can it work at all?
Yes, if there is an error, it jumps to .catch and executes whatever is in .catch. So you need to make sure you include in .catch what you want to happen if there is an error. If you need to address errors individual, pass two functions to each .then.
Does console.log(def) at 21:33 need to be asynchronous?
Thanks for the question. It is asynchronous because it is in response to a promise, in the then statement.
This concept ain't so easy. It takes multiple iterations to master. I watch your videos more than once. This one is almost excellent!
Don of javascript == Sir, Steven Hancock.
Thanks a lot! This was much easier for me to understand compared to other videos I watched
Thank you for the deep explanation and simple example of what is promises in JavaScript
Wonderful tutorial on promises. Where is the code of asyncFunction( ) ? I mean the body of asyncFunction( ). Your voice is clear and the way you explain with example code is too good. The best teacher on javascript award goes to you :-) .
Thanks for the positive feedback! The asyncFunction is in a separate JS file attached to the same HTML page. I just separated it to simulate a function that might not be a part of your own code.
I really understand what a PROMISE really is because of you. Simple explanation thank you so much..
Thanks for the feedback! That helps me continue doing this.
I nearly gave up on Promises until I watched this video. Thank You so much
Glad I could help!
Hi Steve, can you please post the contents of asyncfunc() and asyncfunc2() ?
I don't remember the exact function but it was simply doing a settimeout I believe. Something like this:
let asyncFunction = function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(asyncFunction has been resolved");
}, 5000)
});
};
@@AllThingsJavaScript finally I find it!!!! It was very important!!!!
Top teaching skills and resources.
I wish we could dine together! We could talk about how to dominate the world with javascript!
you have created asyncFunction() but why you do NOT show the content of it? I have not understood this lesson from the beginning :(
Is your question asking why I created the asyncFunction? Or is there something else you would like me to explain better?
@@AllThingsJavaScript when you type in asyncFunction () in browser it show Promise. What the content inside of asynkFunction ()?
asyncFunction just returns a promise. That is all. It sets a short timer and then returns a promise.
If you haven't yet it may help to watch all the movies in the playlist: ua-cam.com/play/PLTo9PCskHpbHIDnzl8tRYldSCSQaFgAHd.html
Hi Konstantin . . To answer your question , the tutor has set up those promises.
Promises kept, thanks for the lesson, have a good day.
Nice explanation thank you so much.👍👍
Excellent explaination Steve, you did not mention that promise.then() / catch() methods return a promise in turn, if I am not wrong.
You are correct! then and catch both return promises.
Thank you for explaining it well. But I just have one question, does the .then functions itself returns a promise? Because you chained the .catch function to the .then function.
The then method doesn't return a promise, but may contain something that returns a promise.
Beautiful teaching .... well explained!
getting an error, async function is not defined....help!
Can you post code? If you are trying to use the same code as the tutorial, remember I defined an async function in a different JS file.
@@AllThingsJavaScript
Sorry, I missed the function defined in the other JS file
Great work. Thank you very much👍
Sir i am not able to understand ..a function that returns promise which converts the given array of string into uppercase and returns the result after n seconds, where n is the length of input array.
Which part are you having difficulty with? Have you viewed the entire playlist on promises?
so it is always better to convert data to json ?
When using fetch it is how you access the data. You use the json method to convert the data to a format you can work with.
@@AllThingsJavaScript thank you! n really precise video🤗
is it possible that output of one promise can be use as input for another promise. If yes can you direct me how to do that.
I must say the most meaning video on chaining. Thanks a lot and keep up the good work
Yes, you would do that by issuing another promise. Does that help?
very well structured video ;)
Hello sir,
Please tell me what is array-like object and how do create own array-like object?
Am new in JavaScript
An array like object is simply an object that has a length property and then some indexed properties. So it has features of an Array, but was not created with the array literal ([]) or array constructor (new Array()). I'm not sure why you would want to create one, just create an array. However, sometimes these are created for you. For example, a node list (when you select HTML nodes) and the arguments of a function are array like. Usually we convert array like objects to arrays in order to work with them. Here is a tutorial: ua-cam.com/video/avPIXAftj24/v-deo.html
Thank you!
Great! One thing that I find odd is..where is the asyncFunction () and asyncFunction2 () declarations?
BTW, I love all your tutorials, please keep up the good work!
They are in a separate JS file.
@@AllThingsJavaScript That confused me as well
@@AllThingsJavaScript what's inside asyncFunction () function ? I am curious to know about the promises codes written inside the function .
@@anishkc1831 It just has a setTimeout is all. It looks something like this:
let asyncFunction = function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve("asyncFunction has resolved.");
}, 4000);
});
};
@@AllThingsJavaScript thank you for a great tutorials bundle with depth knowledge
Can not believe from all my classes it the course where i get the closest of understanding it but hahah still the logic escape me terrible hey lol I will get it :)
Dry-hole? :| Amazing video but that totally distracted me! xD
for beginner, it's tough to understand the JS promises concept from this video. I only managed to get little understanding from this video.
As a beginner I wouldn't suggest learning promises from the start. I would recommend starting with the basics first. Perhaps a book or a course to get the basics down and then you can add to it.
If you are interested in my getting started course let me know. I'm not trying to sell this to you, I just think you would avoid a lot of frustration by learning the basics first. Good Luck! Stick with it!
cool
2021-09-20}
The concept is easy, the syntax is confusing !! in JavaScipt so many brackets etc..etc... and all tutorials assume you known the syntax frustrating !!!
Which syntax elements are confusing? We can help clarify it.
@@AllThingsJavaScript anonymous functions that have no name such as function(val) , is that a self evoking function?
@@vinayn9110 This is really considered a callback. I've got multiple tutorials on callbacks you may want to look at. This is a declared functions that is passed into another function; in this case the then method of a promise. The then method is then responsible for invoking that function. Callbacks can be a bit confusing, but are vary powerful. Here are links to a couple of tutorials: ua-cam.com/video/Nau-iEEgEoM/v-deo.html and ua-cam.com/video/tBjvWZn9fvs/v-deo.html
@@AllThingsJavaScript thank you very much.