// example of async and await in javascript
// First create promise
let myPromise = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Yay, I resolved!')
}, 1000);
});
}
// async without await keyword
async function noAwait() {
let value = myPromise();
console.log(value);
}
// async with await keyword
async function yesAwait() {
let value = await myPromise();
console.log(value);
}
noAwait(); // Prints: Promise { <pending> }
yesAwait(); // Prints: Yay, I resolved!