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.
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter