@@akshaymarch7 No problem, you truly deserve all the support and encouragement to keep creating such videos for sharing knowledge in such simplest way. And it's not only useful for newcomers, but also for many experienced people like me to strengthen their basics about Javascript. I truly admire your dedication and desperation to make people understand the concept thoroughly. Just keep it up!!
currently I am pursuing mca from ignou (open) and before that I have done bsc mathematics .I am fresher .I wants to work at top companies.many of friends are telling with these degrees I cant join top mnc as they dont give preference to open degree .I am very much frustrated .is it TRUE?
@akshaymarch7 currently I am pursuing mca from ignou (open) and before that I have done bsc mathematics .I am fresher .I wants to work at top companies.many of friends are telling with these degrees I cant join top mnc as they dont give preference to open degree .I am very much frustrated .is it TRUE?
This Episode is a little long, but trust me everything taught is super important. Watch this video with full attention and also finish the homework given at the end of this video. All the Best. Keep Rising! 🚀
1. Promise can be created using a new Promise() constructor function. 2. This constructor function takes a callback function as argument. 3. The callback function has 2 arguments named 'resolve' and 'reject'. Resolve and reject are the keywords provided by JS. 4. We can only resolve or reject a promise. Nothing else can be done. 5. An error can also be created using new Error('error message'). 6. There is also .catch() which is used to attach a failure callback function that handles any error that pops up during the execution of promise chain. 7. .catch only handles error of .then() that are present above it. If there is any .then() below it, catch will not handle any error for that, also that ,then will get executed no matter what. 8. It can be useful in a way if we want to catch error for a particular portion of a chain. 9. We can have multiple catch based on requirement and then a general catch at the end. 10. Always remember to return a value in the promise chain for the next .then to use . 11. If it returns a value => It will be used as an argument in next function. If it is a promise then the next .then in the promise chain is attached to the promise returned by the current callback function. Homework: const cart = ['shoes', 'pants', 'kurta']; createOrder(cart) .then(function(orderId) { console.log(orderId); return orderId; }) .then(function(orderID) { return proceedToPayment(orderID) }) .then(function({ message, amt }) { console.log(message, 'of amount:', amt); return showOrderSummary(message, amt); }) .then(function({ message, amt }) { console.log('Your wallet has beed debited by:', amt); }) .catch(function(err) { console.log(err.message); }) .then(function() { console.log('No matter what happens, I will get executed'); }); function createOrder(cart) { const pr = new Promise(function(resolve, reject) { // create order // Validate Cart // orderId if (!validateCart(cart)) { const err = new Error('Cart is not valid!'); reject(err); } // logic for createOrder const orderId = '12345'; if (orderId) { setTimeout(function() { resolve(orderId); }, 5000) } }); return pr; } function proceedToPayment(orderID) { // Logic for handling payment. // This function returns a promise return new Promise(function(resolve, reject) { // logic resolve({ message: `Payment Successful for order id: ${orderID}`, amt: 2500 }); }) } function showOrderSummary(paymentInfo, amt) { return new Promise(function(resolve, reject) { // console.log(amt); if (amt >= 2000) { resolve({ message: 'You have ordered items that cost ${amt} RS', amt }); } else { reject(new Error('Please buy more for discount')); } }) } function validateCart(cart) { // code to validate cart. return true; // return false; }
If you are really interested to learn or know something really important, then you won't bother about the length of the video. No trash, No Bakwaas, just pure concepts and real-time things. I loved it. Big hug Akshay 🤗.
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
I really like lengthy videos if they are actually going deep into the concepts like you. So please continue doing this and please again start off this season. I am waiting for the other topics
Hi Akshay, thank you so very much on JS. You won't believe. U achieved ur target of making viewers fall in love with JS. Yes, I already fell in love with JS. All credit goes to you. Thank you once again!! Have you created any video on arrow functions?? If not, can you please create one?? Just want to know its practical importance and how and where it becomes better/advantageous than normal functions in javascript. There are many videos on it but nothing explains from the root of concepts like you?? Thanks in advance!!
Thank you Akshay, you clarified my mind, I really had a lot of confuses before. But u put everything in order and gave clear understanding! I appreciate it and I'll share all of ur videos with my friends, cause your tutorials are really best❤👏👏👏
Hello Sir ! These two promises video made my concept regarding promises very clear. When are the further videos in this series coming. We are waiting for new things to learn from you
Thanks Akshay for distilling JavaScript into your super easy videos. I just loved it. You're giving your precious time to teach all of us here, Kudos to you. Looking forward to your next awesome video.
completed season 1 and season 2 till episode 3, Iam much confident in javascript now .Thankyou very much for putting this excellent content for free , and bruh you look somehwhat like ravindra jadeja..... 😅😅
@Ranjan - Why did you pay for the school where you studied ! It is available free does not mean there are no efforts given. It might be his kindness that he gave it for free. But at the same I felt that he might need to setup and what not other expenses for all these sessions. Hence I paid and believe me the money I paid is just a way of thanking him and his efforts ! Not a necessity. I hope i was able to answer your doubt !
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
lengthy videos are always good akshay bhai , I lost my job due to recession , i have 4 months of nodejs exp , job lagne par i will also support your channel like others , best wishesh waiting for next video . thank you for these videos.
where is the next part of this videos it's into this playlist. if u have already made that video then plz update this playlist else made that video plz . And also try to make some videos on the frontend project . that would be very helpful .. Tqs for such content......
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
I had an interview a couple of days back. The interviewer asked me how we can continue executing few "then" blocks even if we have an error from one of them. To be honest, I didn't understand his question then. Now I know what he meant and have the answer after watching this video. Thanks so much Akshay !
Akshay just want to say a big thank you. i have been working for over 10 years in IT industry but the clarity of javascript given by you for core concepts is invaluable. Not only it helped me in interviews but also helped to be a better developer. Amazing work!!! I hope you'll amaze us every time and keep the good content coming :)
Hii Akshay, waiting for the next video for the last 4 months, please upload new videos, initially, your videos are like a headache because it was too depth and lengthy but slowly realized that this was material that all freshers looking for to become good developers with a better understanding.
Nowadays everyone is creating for beginners or a so called crash course but.... As developer I want to see such kind of videos where you will see deep scenario and realtime code debugging we like this length of videos Kudos to you Akshay bhaiya❤️
Bro you are truly legend...you made me fall in love with JavaScript 😂... keep teaching us...lots of respect for you... length is not a matter until unless it has a content..... 🙏✌
We want these type of content we will support you i will support you through your courses i will buy all your courses currently i bought your react course in future once i will get a job defnitely i will buy your frontend system design i am in hungry mode to learn your content
You deeply dived in this topic Bro. Such a difficult topic you conway us easily. Once i got job i will defiantly give token thanks in $... Love your passion to teach ❤️
Please don't reduce video length. We need these dive deeper kinda videos otherwise there are tons of videos available on youtube explaining promises in just 5-10 mins.
Thank you so much Akshay for such amazing learning content❤ I invested in Namaste React course in the end of last year, currently learning new in depth about React. And I am very excited for your future Namaste System Design course and DSA course too. Feel soo good to invest in such amazing courses for growth. ❤
It was super fun for me to learn these concepts for the first time and from the best teacher. Thank you for everything🙏 Here is my homework. --------------------------------------------------------------------------------------------- const cart = ["Shirt", "Jeans", "Shoes", "Watch"]; let walletBalance = 10000; // Promise Chain createOrder(cart) .then(function(orderId){ console.log(orderId); return orderId; }) .then(function(orderId){ return proceedToPayments(orderId) }) .then(function(amount){ console.log(`"Your payment of Rs. ${amount} is Successful`) return amount; }) .then(function(amount){ return showOrderSummary(amount); }) .then(function(orderSummary){ console.log(orderSummary) return orderSummary; }) .then(function(amount){ return updateWalletBalance(amount); }) .then(function(updateWalletBalance){ console.log(`Your updated wallet balance is ${updateWalletBalance}.`); return updateWalletBalance; }) .catch(function(error){ console.log(error.message); }) ; // Create Order function createOrder(cart){ return promise1 = new Promise(function (resolve, reject) { if(validOrder(cart)){ const orderId = "76513"; resolve(orderId); } else { const error = new Error("Your Cart is Empty"); reject(error); } }) } // Proceed to Payment function proceedToPayments(orderId){ return promise2 = new Promise(function (resolve, reject){ if(payment(orderId)){ const amount = 4600; resolve(amount); } else{ const error = new Error("Payment failed!") reject(error); } }) } // Show order summery function showOrderSummary(amount){ return promise3 = new Promise(function(resolve, reject){ const orderSummary = amount; resolve(orderSummary); const error = new Error("Something went wrong!") reject(error); }) } // Update Wallet Balance function updateWalletBalance(amount){ return promise4 = new Promise(function(resolve, reject){ const updatedWalletBalance = walletBalance-amount; resolve(updatedWalletBalance); const error = new Error("Failed to update wallet balance") reject(error); }) } // Payment function payment(){ return true; } // Validating order function validOrder(){ if(cart.length == 0) return false else return true; }
Promise is an object which represent the evntual completion of assynchronous operation Advantages :It avoid the problem arising from the call back hel which creates the pyramid like structure horizontally which is not able to understand the code when others seen first And inversion of control And it is in a structured formate and like we can easily execute the task with consecutively which is good one
A couple of things which could be added to the video(maybe in the next) : 1) "Catch" is not just for the method like createOrder rejecting things but any error which can occur within the then's callback as well. 2) "then" takes two callbacks for resolved and rejected case, even though that's not a pattern we Devs generally follow and because it's not handled it gets passed down to "catch" . 👍
1.resolve accepts only one argument (if we have more arguments either pass through object or array ) 2.By using the Promise constructor we can new promise and inside the promise we need to give the call back function with passing resolve and reject 3.two phases creation phase and consuming phase 4..then() must and should return new promise if we wish to extend the .then()(promise chain)
Excellent videos! Thank you. Please produce more like these, I love how you simplify things and make everything make sense and don't worry about the length! Serious learners will sit through hours of video if the content is high quality like this!
Oh, I'm very excited because I got heart react from Akshay Sir😃. I thought that the series is old and Akshay bhai is no longer seeking comment. But you read my comment. I hope you also check this commend as well and I want to say that. I'm your big fan sir!!! Amazing skill and explanation. You are wonderfull. Lot of love from my side Akshay bhai. Just superb smile and attitude. God bless you and your family more and more.💝🥰😍
promises are important to maintain the trust for example when the coontrol of program is send to particular api then we cant rely on what will it return that is it can return 2 times the value or nothing so promises store the value return in a empty container and then using .then they can be called
Hi Akshay , Your tutorials are extremely helpful. I just wanted to ask you how you obtain auto suggestions for the next code, also did you use any extensions for it.
26:12 i have doubt here the orderId is just a simple datatype , not promise right ? so how you can use then after it... we can use then only when the returned object is promise right ?
Excellent video! One doubt only when you wrote the last code, you used catch two time. One after the catch order and one after the payment info. But it get printed only once. Why does that happen? Please resolve
Excellent stuff, Thanks Akshay!
Thank you so much for supporting my channel, Sujit. This means a lot. ❤️
@@akshaymarch7 No problem, you truly deserve all the support and encouragement to keep creating such videos for sharing knowledge in such simplest way.
And it's not only useful for newcomers, but also for many experienced people like me to strengthen their basics about Javascript.
I truly admire your dedication and desperation to make people understand the concept thoroughly.
Just keep it up!!
I like to pay but I don't have any money
Sorry for taking stuff free
currently I am pursuing mca from ignou (open) and before that I have done bsc mathematics .I am fresher .I wants to work at top companies.many of friends are telling with these degrees I cant join top mnc as they dont give preference to open degree .I am very much frustrated .is it TRUE?
@akshaymarch7 currently I am pursuing mca from ignou (open) and before that I have done bsc mathematics .I am fresher .I wants to work at top companies.many of friends are telling with these degrees I cant join top mnc as they dont give preference to open degree .I am very much frustrated .is it TRUE?
This Episode is a little long, but trust me everything taught is super important. Watch this video with full attention and also finish the homework given at the end of this video. All the Best. Keep Rising! 🚀
always
I'm watching this video over and over again... It's so addictive.
Akshay sir, Please make a vedio on polyfill concepts...🙏🙏
akshay sir, you didn't upload any more videos ? everything is good ?
Hi Akshay, when can we expect video on Async await and how it is better than promise chaining.. ?
when can we expect EP-04 ???
you made me fall in love with JavaScript, Amazing content
fr it made me fall in love too
Big Thanks to Akshay sir
Pls bring the EP04, waiting for it.
Ha Bhai daalo age k videos yaar jaldi jaldi
Thank you so much for supporting my channel. This means a lot. ❤️
1. Promise can be created using a new Promise() constructor function.
2. This constructor function takes a callback function as argument.
3. The callback function has 2 arguments named 'resolve' and 'reject'. Resolve and reject are the keywords provided by JS.
4. We can only resolve or reject a promise. Nothing else can be done.
5. An error can also be created using new Error('error message').
6. There is also .catch() which is used to attach a failure callback function that handles any error that pops up during the execution of promise chain.
7. .catch only handles error of .then() that are present above it. If there is any .then() below it, catch will not handle any error for that, also that ,then will get executed no matter what.
8. It can be useful in a way if we want to catch error for a particular portion of a chain.
9. We can have multiple catch based on requirement and then a general catch at the end.
10. Always remember to return a value in the promise chain for the next .then to use .
11. If it returns a value => It will be used as an argument in next function. If it is a promise then the next .then in the promise chain is attached to the promise returned by the current callback function.
Homework:
const cart = ['shoes', 'pants', 'kurta'];
createOrder(cart)
.then(function(orderId) {
console.log(orderId);
return orderId;
})
.then(function(orderID) {
return proceedToPayment(orderID)
})
.then(function({ message, amt }) {
console.log(message, 'of amount:', amt);
return showOrderSummary(message, amt);
})
.then(function({ message, amt }) {
console.log('Your wallet has beed debited by:', amt);
})
.catch(function(err) {
console.log(err.message);
})
.then(function() {
console.log('No matter what happens, I will get executed');
});
function createOrder(cart) {
const pr = new Promise(function(resolve, reject) {
// create order
// Validate Cart
// orderId
if (!validateCart(cart)) {
const err = new Error('Cart is not valid!');
reject(err);
}
// logic for createOrder
const orderId = '12345';
if (orderId) {
setTimeout(function() {
resolve(orderId);
}, 5000)
}
});
return pr;
}
function proceedToPayment(orderID) {
// Logic for handling payment.
// This function returns a promise
return new Promise(function(resolve, reject) {
// logic
resolve({ message: `Payment Successful for order id: ${orderID}`, amt: 2500 });
})
}
function showOrderSummary(paymentInfo, amt) {
return new Promise(function(resolve, reject) {
// console.log(amt);
if (amt >= 2000) {
resolve({ message: 'You have ordered items that cost ${amt} RS', amt });
} else {
reject(new Error('Please buy more for discount'));
}
})
}
function validateCart(cart) {
// code to validate cart.
return true;
// return false;
}
Thanks brother 🙏
Bhai mai namaste javascript wali hrr ek video k comment section m tumko dhoondhta hu, video khatam hona k baad
@@python-gamer9711 His name is reflect is work... isin' tit. 😊
Bhai aapka knowledge toh kamaal ka hai bhai.
@@harshmohite6297 sahi baat hai
If you are really interested to learn or know something really important, then you won't bother about the length of the video. No trash, No Bakwaas, just pure concepts and real-time things. I loved it. Big hug Akshay 🤗.
Thank you so much for supporting my channel, Abhishek. This means a lot. ❤️
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
Thank you so much for supporting my channel, Ishant. This means a lot. ❤️
Consistency at it's best❤️
Thank you so much for supporting my channel, Pravin. This means a lot. ❤️
@@akshaymarch7 please make a video on arrow function
I really like lengthy videos if they are actually going deep into the concepts like you. So please continue doing this and please again start off this season. I am waiting for the other topics
Hi Akshay, thank you so very much on JS. You won't believe. U achieved ur target of making viewers fall in love with JS. Yes, I already fell in love with JS. All credit goes to you. Thank you once again!! Have you created any video on arrow functions?? If not, can you please create one?? Just want to know its practical importance and how and where it becomes better/advantageous than normal functions in javascript. There are many videos on it but nothing explains from the root of concepts like you?? Thanks in advance!!
Thank you Akshay, you clarified my mind, I really had a lot of confuses before. But u put everything in order and gave clear understanding! I appreciate it and I'll share all of ur videos with my friends, cause your tutorials are really best❤👏👏👏
Most beautiful playlists on JavaScript.
Binge watched the 23+4=27 videos in 3 days.
*Please continue this series.*
Just blown away when you said what happens when we just reject and do not handle errors.
Hello Sir ! These two promises video made my concept regarding promises very clear. When are the further videos in this series coming. We are waiting for new things to learn from you
Brother Litterally Love u I could'nt Find Anyone Except you to explain things in this style solute u bro 💕💕
Thanks Akshay for distilling JavaScript into your super easy videos. I just loved it. You're giving your precious time to teach all of us here, Kudos to you. Looking forward to your next awesome video.
Thank you so much for supporting my channel, Manohar. This means a lot. ❤️
@@akshaymarch7 bro when can we expect the next video
completed season 1 and season 2 till episode 3, Iam much confident in javascript now .Thankyou very much for putting this excellent content for free , and bruh you look somehwhat like ravindra jadeja..... 😅😅
Thanks a lot for all your awesome videos. I know and respect each and every efforts behind each video !
Thank you so much for supporting my channel, Ganesh. This means a lot. ❤️
Hi Ganesh. Y are u paying money to Akshay?
@Ranjan - Why did you pay for the school where you studied !
It is available free does not mean there are no efforts given. It might be his kindness that he gave it for free. But at the same I felt that he might need to setup and what not other expenses for all these sessions. Hence I paid and believe me the money I paid is just a way of thanking him and his efforts !
Not a necessity. I hope i was able to answer your doubt !
@@ganeshkhirwadkar4127 that's great initiative from your side. I will also pay.
Thanks for your ans👍☺️
well answered@@ganeshkhirwadkar4127
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
Bhai...! Kya hi bolu main aapko! Just take my 🙏Namaskar🙏
You don't know how many problems of developers you've solved just by this video.
Akshay you are great...you made me fall in love with JavaScript 😂... keep teaching us...lots of respect for you
Your videos should be at least 1 hour long.....they teaches us a lot, Take love from Pakistan 🇵🇰❤️🇮🇳
lengthy videos are always good akshay bhai , I lost my job due to recession , i have 4 months of nodejs exp , job lagne par i will also support your channel like others , best wishesh waiting for next video . thank you for these videos.
where is the next part of this videos it's into this playlist. if u have already made that video then plz update this playlist else made that video plz . And also try to make some videos on the frontend project . that would be very helpful .. Tqs for such content......
These are lengthy videos but are totally worth it. Please keep making similar videos. Don't worry about the length of the video. Just keep doing the good work Akshay. Promise is a very confusing topic, and you are making it very easy. Please make more videos on promises.
I had an interview a couple of days back. The interviewer asked me how we can continue executing few "then" blocks even if we have an error from one of them. To be honest, I didn't understand his question then. Now I know what he meant and have the answer after watching this video. Thanks so much Akshay !
When i see your videos , the fingers go automatically at the like button
Seedhi baat no bakwaas ,love you ❤❤
It's here😍. For the first time in my life, I'm excited that a video is long, because I know I'll definitely get more quality content.
Length of video is not a problem at all, we would love to hear you hours together with such lovely content.
Akshay just want to say a big thank you. i have been working for over 10 years in IT industry but the clarity of javascript given by you for core concepts is invaluable. Not only it helped me in interviews but also helped to be a better developer. Amazing work!!!
I hope you'll amaze us every time and keep the good content coming :)
Hii Akshay, waiting for the next video for the last 4 months, please upload new videos, initially, your videos are like a headache because it was too depth and lengthy but slowly realized that this was material that all freshers looking for to become good developers with a better understanding.
Now onwards it's super easy to keep promises in mind.😅
Thanks for this amazing content.😇
Thank you so much for supporting my channel, Pratyush. This means a lot. Happy Diwali ❤️
Happy Diwali 🎇🎇
bahut ache se explain kiya hai . kahin aur se padhne ki jarurat hi nhi
Nowadays everyone is creating for beginners or a so called crash course but.... As developer I want to see such kind of videos where you will see deep scenario and realtime code debugging we like this length of videos Kudos to you Akshay bhaiya❤️
bhai tu developer bna kaise fir
@@himanshuarora1910 after creating to do list
It is only a joke!
Bro you are truly legend...you made me fall in love with JavaScript 😂... keep teaching us...lots of respect for you... length is not a matter until unless it has a content..... 🙏✌
I binge-watched your JS series; Thank you for all the "Aha!" Moments. You are Pushpa and JS is Red-sanders; Thagede Le!
My solution to the problem:
const cart = ["Bitcoin", "Glasses", "Kurta", "Jacob & Co", "Xbox"]
let order
createOrder(cart)
.then(function (orderId) {
order = orderId
return proccedToPayment(orderId)
})
.then(function (pin) {
return showOrderSummary(pin)
})
.then(function (msg) {
updateWallet(order, msg)
})
.catch((err) => {
console.log(err)
})
function createOrder(items) {
return new Promise((reslove, reject) => {
if (items.length >= 5) {
console.log("Order: 49591214")
reslove(49591214)
} else {
const err = new Error("Add more Items. Items must be >=5")
reject(err)
}
})
}
function proccedToPayment(orderId) {
return new Promise((reslove, reject) => {
setTimeout(() => {
if (orderId === 49591214) {
console.log("OrderID: 49591214 Enter your UPI Pin")
const pin = 13579
reslove(pin)
} else {
const err = new Error("Payment not succesful")
reject(err)
}
}, 5000)
})
}
function showOrderSummary(pin) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (pin === 135790) {
resolve("Payment Succesful! Order Created: ")
} else {
const err = new Error("WRONG PIN!")
reject(err)
}
}, 4000)
})
}
function updateWallet(order, msg) {
console.log(msg + order)
}
Thank you so much for supporting my channel. This means a lot. ❤️
Thank you for explaining this concepts.
Bro start teaching REACTJS. Your really great inspiration for me.
We want these type of content we will support you i will support you through your courses i will buy all your courses currently i bought your react course in future once i will get a job defnitely i will buy your frontend system design i am in hungry mode to learn your content
You deeply dived in this topic Bro. Such a difficult topic you conway us easily. Once i got job i will defiantly give token thanks in $...
Love your passion to teach ❤️
first like and first comment
respect from egypt 🇪🇬
Ali
best wishesh waiting for next video . thank you for these videos.
Your videos helped me in cracking an interview
Thank you so much for supporting my channel. This means a lot. ❤️
At the start it's struggles me, but at the end, i fully understand it. The multiple catch was great. Keep this way!
Akshay big thanks to you for make such kind of videos. I really appreciate your teaching technique for deep concepts.
const cart = [
{
itemName : 'Shoes',
itemPrice : 2000
},
{
itemName : 'Paint',
itemPrice : 2500
},
{
itemName : 'Kurta',
itemPrice : 1500
}
];
let walletBalance = 10000;
createOrder(cart)
.then(function(orderId){
return orderId;
})
.then(function(orderId){
return proceedToPayment(orderId);
})
.then(function(orderStatus){
return showOrderSummery(orderStatus);
})
.then(function(orderHistory){
return updateWallet(orderHistory);
})
.then(function(res){
console.log(res);
})
.catch((err)=>{
console.log(err.message)
})
function createOrder(cart){
return new Promise(function(resolve,reject){
if(!validateCart(cart)){
reject(new Error("Cart is not valid"));
}
let orderId=10
if(orderId){
resolve(orderId);
}
})
}
function proceedToPayment(orderId){
return new Promise(function(resolve,reject){
if(orderId){
resolve({paymentStatus : 1, message : "Payment successfully completed"});
}else{
reject(new Error("Payment Failed"));
}
})
}
function showOrderSummery(orderStatus){
return new Promise(function(resolve,reject){
if(orderStatus.paymentStatus === 1){
resolve({status:'success', orders : cart});
}else{
reject(new Error("Something went wrong"));
}
})
}
function updateWallet(orderHistory){
return new Promise(function(resolve,reject){
if(orderHistory.status === 'success'){
let orderAmount = 6000;
walletBalance = walletBalance - orderAmount;
resolve({balance : walletBalance, 'message':'Wallet updated'});
}else{
reject(new Error("Wallet balance not updated"));
}
})
}
function validateCart(cart){
return true;
}
If any kind of suggestion for my code please tell me.✍
createOrder(cart)
.then(orderId => orderId)
.then(orderId => proceedToPayment(orderId))
.then(orderStatus => showOrderSummery(orderStatus))
.then(orderHistory => updateWallet(orderHistory))
.then(res => console.log(res))
.catch(err => console.log(err.message))
Nicely written bro
Awesome bro @omprakashmaurya
Same solution with async/await
async function getOrderDetails() {
const orderId = await createOrder(cart)
console.log(orderId)
const orderStatus = await proceedToPayment(orderId)
const orderHistory = await showOrderSummary(orderStatus)
const response = await updateWallet(orderHistory)
const finalResult = await (function(){
return response
}(response))
console.log(finalResult)
}
getOrderDetails()
@@senthamarai_kannan. You should return the parameters like order Id and proceedToPayment and all
Like all your videos, it's excellent. I look forward to the ASYNC/AWAY theme. I hope you also consider the topic of GENERATORS.
Waiting for next video on promises like you mentioned combining result of two promises, etc.
Your playlist helped me a lot in my career.
Thanks Akshay
Thank you so much Pavan, this means a lot! ♥️
Promise us to Teach forever 😍 🔥
Please don't reduce video length. We need these dive deeper kinda videos otherwise there are tons of videos available on youtube explaining promises in just 5-10 mins.
beyond words!! this is the best promise chaining video on internet!!! thanks buddy!
Thank you so much Akshay for such amazing learning content❤
I invested in Namaste React course in the end of last year, currently learning new in depth about React.
And I am very excited for your future Namaste System Design course and DSA course too. Feel soo good to invest in such amazing courses for growth. ❤
It was super fun for me to learn these concepts for the first time and from the best teacher. Thank you for everything🙏
Here is my homework.
---------------------------------------------------------------------------------------------
const cart = ["Shirt", "Jeans", "Shoes", "Watch"];
let walletBalance = 10000;
// Promise Chain
createOrder(cart)
.then(function(orderId){
console.log(orderId);
return orderId;
})
.then(function(orderId){
return proceedToPayments(orderId)
})
.then(function(amount){
console.log(`"Your payment of Rs. ${amount} is Successful`)
return amount;
})
.then(function(amount){
return showOrderSummary(amount);
})
.then(function(orderSummary){
console.log(orderSummary)
return orderSummary;
})
.then(function(amount){
return updateWalletBalance(amount);
})
.then(function(updateWalletBalance){
console.log(`Your updated wallet balance is ${updateWalletBalance}.`);
return updateWalletBalance;
})
.catch(function(error){
console.log(error.message);
})
;
// Create Order
function createOrder(cart){
return promise1 = new Promise(function (resolve, reject) {
if(validOrder(cart)){
const orderId = "76513";
resolve(orderId);
} else {
const error = new Error("Your Cart is Empty");
reject(error);
}
})
}
// Proceed to Payment
function proceedToPayments(orderId){
return promise2 = new Promise(function (resolve, reject){
if(payment(orderId)){
const amount = 4600;
resolve(amount);
} else{
const error = new Error("Payment failed!")
reject(error);
}
})
}
// Show order summery
function showOrderSummary(amount){
return promise3 = new Promise(function(resolve, reject){
const orderSummary = amount;
resolve(orderSummary);
const error = new Error("Something went wrong!")
reject(error);
})
}
// Update Wallet Balance
function updateWalletBalance(amount){
return promise4 = new Promise(function(resolve, reject){
const updatedWalletBalance = walletBalance-amount;
resolve(updatedWalletBalance);
const error = new Error("Failed to update wallet balance")
reject(error);
})
}
// Payment
function payment(){
return true;
}
// Validating order
function validOrder(){
if(cart.length == 0) return false
else return true;
}
you are legend in JavaScript world
waiting for episode 4, hope you will make it fast.🥰🥰
No vedios
Please make video on Object oriented programming Akshay
Promise is an object which represent the evntual completion of assynchronous operation
Advantages :It avoid the problem arising from the call back hel which creates the pyramid like structure horizontally which is not able to understand the code when others seen first
And inversion of control
And it is in a structured formate and like we can easily execute the task with consecutively which is good one
The way you explain the concepts is awesome. If you can also create videos on oops and solid principals, it would be very useful.
Thank You Akshay for creating such videos with in-depth clarity. Looking forward to more episodes of season 2.
A couple of things which could be added to the video(maybe in the next) : 1) "Catch" is not just for the method like createOrder rejecting things but any error which can occur within the then's callback as well. 2) "then" takes two callbacks for resolved and rejected case, even though that's not a pattern we Devs generally follow and because it's not handled it gets passed down to "catch" . 👍
1.resolve accepts only one argument (if we have more arguments either pass through object or array )
2.By using the Promise constructor we can new promise and inside the promise we need to give the call back function with passing resolve and reject
3.two phases creation phase and consuming phase
4..then() must and should return new promise if we wish to extend the .then()(promise chain)
sir, please continue this series... i am really enjoying it
Excellent videos! Thank you. Please produce more like these, I love how you simplify things and make everything make sense and don't worry about the length! Serious learners will sit through hours of video if the content is high quality like this!
Your videos and your way of explainig is really great . Worth every second ...
The best part of your all videos is "Your smile at end" 😃😅 Tremendous
Oh, I'm very excited because I got heart react from Akshay Sir😃. I thought that the series is old and Akshay bhai is no longer seeking comment. But you read my comment. I hope you also check this commend as well and I want to say that. I'm your big fan sir!!! Amazing skill and explanation. You are wonderfull. Lot of love from my side Akshay bhai. Just superb smile and attitude. God bless you and your family more and more.💝🥰😍
Totally... the happiness we all resonate with :)
Please continue this series.
Thanks!
Thank you so much for supporting my channel, Martin. This means a lot. ❤️
Please continue this series.
Thanks
Thank you so much for supporting my channel, Sandeep. This means a lot. ❤️
promises are important to maintain the trust for example when the coontrol of program is send to particular api then we cant rely on what will it return that is it can return 2 times the value or nothing so promises store the value return in a empty container and then using .then they can be called
Its a great content Akshay! We definitely want to dive deep through examples. Its ok if videos are getting longer as the content is real gold
Please cover all concepts and don't worry about the length of videos 🙏
Thanks!
Thank you so much for supporting my channel, John. This means a lot. ❤️
(shorts) => { return "beneficial over short time" }
(long_videos) => { return "beneficial long time" }
No words :) Just amazing you made the promise so easy to understand waiting for more such content 😎🔥🚀
@Akshay saini sir i think you need to look into this looks scam to me 🤔
@@abhishekvishwakarma9045 yeahhhhhh many comments have this reply
This can be easily done with async await. please cover that in upcoming videos. thanks in advance
Thanks Akshay...
Thank you so much for supporting my channel, Vipul. This means a lot. ❤️
waiting for next epi.
level of stufs are really good .
hey Akshay, when is Async await video coming up?
Loving and learning your videos, please create such videos..worth watching your videos bro.. you’re awesome ❤
A video on async await will be very helpful.
Really valuable content Akshay!! Thanks a lot for all your endeavor 😊
Looking forward for more such helpful content😁
The explanation for last "then" to be executed is that "catch" also returns a "promise" which is then-able.Therefore , the last then is executed.
Why are you very slow in putting videos
He started namaste react
Bahot mehenga hai...🥶🥶
Delaying JavaScript for Teaching REACT is very very Wrong decision. When he is putting 1 video per month to aage ka kese yaad rahega...
Hi Akshay , Your tutorials are extremely helpful. I just wanted to ask you how you obtain auto suggestions for the next code, also did you use any extensions for it.
Need a video on JS is single threaded or multi-threaded and libuv explanation pleaseeeeee
Make lengthy videos with in-depth information, thank you in advance.
Lot of respect for you brother.
thanks it was so helpful, waiting for next episode
It was cristal clear superb.....
Why don't you give Fake API calls to give more precise on resolve()👍
Thanks Akshay for the wonderful video.When will we have next video(EP 4) in season 2? Waiting for it :)
26:12 i have doubt here the orderId is just a simple datatype , not promise right ? so how you can use then after it... we can use then only when the returned object is promise right ?
not really you can pass in data or promise through then block
7 months have passed, seems Akshay forgot about his youtube channel.
11:11 if it runs the reject then it will not go down the line, (line 19)
You had the option to name this video “Promise-chan” and you missed it😂
huge respect
Excellent video! One doubt only when you wrote the last code, you used catch two time. One after the catch order and one after the payment info. But it get printed only once. Why does that happen? Please resolve
Upload more videos in this season, please!
love you millions time💖💖💖💖💖💖.....💖💖and a million times thanks