+ 1
How can I use Promises in JavaScript?
I can't understand what are the Promises in JavaScript and how can I use them. Please, someone try to teach me in a way that os easy to understand. If you note some grammar error, sorry, I'm learning English too.
1 Resposta
+ 2
For creating a function that returns promise use async and await e.g.:- async function a(){return await new Promise((r,e)=>{
//You can now perform a simple Ajax call here
//r() function will be called when the promise is resolved and e() will be called when error occurred
});}
async means asynchronous i.e real-time and await will wait for the result until a particular operation is done so if you Ajax call then the promise will only return if the Ajax call is fulfilled.