8
Thu Oct 13 2022 03:29:36 GMT+0000 (Coordinated Universal Time)
Saved by
@Vrushabh_123
async function printDataFromServer() {
const serverData = await anyPromiseWhichWillReturnData() // .then(data => { sksksksksksk(), sjskssks()})
console.log(serverData);
}
// notice that function need an `async` keyword.
// Doing this in es6 arrow function would be
const printDataFromServer = async () => {
try {
const serverData = await anyPromiseWhichWillReturnData();
console.log(serverData);
} catch (err) {
console.error(err)
}
}
/**
Note: In arrow the async keyword is used before the ().
While in normal functions, it is used before the `function` keyword itself.
content_copyCOPY
Comments