why promise js

placeholder :container for future value[eventual completion of async operation]

an object representing eventual compltetion of async operation

 const cart=["shoes","pants","kurta"];


//passing the function

createOrder(cart,function(orderId){

proceedToPayment(orderId);//this is different api how u know it will call 

//or how many times it will call

});


const promise=createOrder(cart);


promise is an object with  empty value

{data:undefined} untill nothing done

after few time the data will be taken


only once after the data will be filled in js...

now the soluation:---

const promise=createOrder(cart);//1

after the data will be filled then called the function attachement..

promise.then(function(orderId){

proceedTopayment(orderId);

});



like we do call api fetch().then(res=>log(res).catch(err=>err);

immutable not change


callback can create call back scenerio as well as

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation