Thank you! THANK YOU! I very rarely comment on videos, but this is just pure gold! It's not an easy concept, and you understand how much beginners may struggle with it. That's why your explanation is so clear. Thank you, again!
This is just too good. I have to admit I did'nt understand this concept from the tutorial bought from Udemy, thanks for your generousity and selflessness!
What is the difference between 'new Promise' and 'return new Promise'? Also you have written resolve with parenthesis "resolve()" and also without parenthesis "resolve". What is the difference here? Thank you for this tutorial.
new Promise() creates the promise. If we add the return keyword in front of it, then it returns that promise from a function. When resolve is a parameter, it receives a function. It acts as a variable that receives a function. When we add parens at the end of it, this forces the function to be invoked.
Please explain what this line of code does let promise = promise(executor(resolve,reject){...... }); What is the role of executor function in this context? how does it get called in back? what does it return ?
Was your intent to use 'new Promise'? There is not enough of the code example to explain what is going on. We need to the declaration for the executor function and is promise suppose to be new Promise? Or is it a call to a function named promise?
@@AllThingsJavaScript Ok let me re-phrase the question When we do let prom = new Promise(executor(resolve,reject){...... }); the Promise Constructor will be called and we will pass this entire executor function to this constructor right. So I want to ask 1) what that constructor will do with this executor function? 2) How it will process this executor and what that constructor will return here? what will be that value. 3) How we will use that return value Actually I see there are many things happening all at once like executor function is sent to the Constructor and the resolve or reject function are also getting called within the executor function at same time. This confuses me a lot with so many things happening. The sequence of events are looking haphazard to me so not able to trace it. With this feeling even if I understand how to write promise syntax not getting satisfied that I fully understood it
@@tusharubale1788 Maybe this will help. When you create a promise, you need to pass a function into the constructor as you have said. The purpose of that function is so you can indicate with code how the promise will work. You indicate when the resolve function is called and when the reject function is called. You define that in the function. Now the act of creating a promise will return a promise. You can then act on that promise using the .then method to pass in a function for resolve and reject. Does that help?
if somebody wanna use the last part with arrow syntax: let setTimeoutPromise = (time) => { return new Promise( (resolve, reject) => { if (isNaN (time)) { reject('a number is required please fill it again below') } setTimeout(resolve, time) }) } setTimeoutPromise('kami') .then( () => { console.log('done') }) .catch( (error) => { console.log(error) })
The reason this happens is because you have included parentheses with your function name. Parentheses tell a function to invoke, so the function invokes before the setTimeout is even finished. You would need to do setTimeout(resolve, 4000);
Thank you! THANK YOU! I very rarely comment on videos, but this is just pure gold! It's not an easy concept, and you understand how much beginners may struggle with it. That's why your explanation is so clear. Thank you, again!
Glad it helped!
You're a very skilled teacher! Thanks, I really appreciate these videos!
I appreciate that!
This is just too good. I have to admit I did'nt understand this concept from the tutorial bought from Udemy, thanks for your generousity and selflessness!
Glad it helped!
Oh, it's the best js promise lesson I ever seen!
Thanks for the positive feedback!
Best tutorial on youtube
Great teaching
Thanks
Thank you so much! This definitely helped me in my overall understanding promises and using them for a bootcamp project due next week...!
You're very welcome!
Great as always... Thank you!!!
Great work, keep it up, you earn respect......
Thank You!
great, clear explanation, thank you
You r great teacher. But the problem is promises is really very difficult topic. So can you make few more tutorials on this
Excellent! Merci beaucoup.
very helpfull, thanks
Having fun rewriting this in ES6:
a.then(val => {console.log(val)}, (val) => {console.log("rejected: "+ val)});
What is the difference between 'new Promise' and 'return new Promise'?
Also you have written resolve with parenthesis "resolve()" and also without parenthesis "resolve". What is the difference here?
Thank you for this tutorial.
new Promise() creates the promise. If we add the return keyword in front of it, then it returns that promise from a function. When resolve is a parameter, it receives a function. It acts as a variable that receives a function. When we add parens at the end of it, this forces the function to be invoked.
Please explain what this line of code does
let promise = promise(executor(resolve,reject){......
});
What is the role of executor function in this context? how does it get called in back? what does it return ?
Was your intent to use 'new Promise'? There is not enough of the code example to explain what is going on. We need to the declaration for the executor function and is promise suppose to be new Promise? Or is it a call to a function named promise?
@@AllThingsJavaScript Ok let me re-phrase the question
When we do
let prom = new Promise(executor(resolve,reject){......
});
the Promise Constructor will be called and we will pass this entire executor function to this constructor right. So I want to ask 1) what that constructor will do with this executor function?
2) How it will process this executor and what that constructor will return here? what will be that value.
3) How we will use that return value
Actually I see there are many things happening all at once like executor function is sent to the Constructor and the resolve or reject function are also getting called within the executor function at same time. This confuses me a lot with so many things happening.
The sequence of events are looking haphazard to me so not able to trace it. With this feeling even if I understand how to write promise syntax not getting satisfied that I fully understood it
@@tusharubale1788 Maybe this will help. When you create a promise, you need to pass a function into the constructor as you have said. The purpose of that function is so you can indicate with code how the promise will work. You indicate when the resolve function is called and when the reject function is called. You define that in the function.
Now the act of creating a promise will return a promise. You can then act on that promise using the .then method to pass in a function for resolve and reject. Does that help?
couldnt thank enough
if somebody wanna use the last part with arrow syntax:
let setTimeoutPromise = (time) => {
return new Promise( (resolve, reject) => {
if (isNaN (time)) {
reject('a number is required
please fill it again below')
}
setTimeout(resolve, time)
})
}
setTimeoutPromise('kami')
.then( () => {
console.log('done')
})
.catch( (error) => {
console.log(error)
})
Thanks for sharing!
When I use setTimeout as: setTimeout(resolve("done"),4000); --> this time it doesnt wait!! Why?
The reason this happens is because you have included parentheses with your function name. Parentheses tell a function to invoke, so the function invokes before the setTimeout is even finished. You would need to do setTimeout(resolve, 4000);
@@AllThingsJavaScript you are great! Thanks
superrb !!!!!!!!!!!