async and await
Write promise code that reads top to bottom — same model, clearer syntax.
An async function always returns a promise.
Inside it, await pauses that function until the
promise settles — it does not freeze the whole page.
This is sugar over .then, not a different system.
Results appear here.
Important JavaScript
async function loadLabel() {
const id = await fetchId();
const player = await fetchPlayer(id);
return player.name + " (" + player.rating + ")";
}
loadLabel().then(function (label) {
console.log(label);
});
// await only works inside async functions (or top-level modules).