The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style.
async function firstAsyncFunction() {
try {
const fulfilledValue = await promise;
}
catch (rejectedValue) {
// …
}
}
async function callAsyncFunction(name){
return new Promise((resolve, reject) => {
resolve(`My name is ${name}`)
})
}
async function getName(name){
const result = await callAsyncFunction(name);
return result;
}
(async () => {
console.log(await getName('Blerona Idrizi'))
})()
The result wil be: My name is Blerona Idrizi