SyntaxErrorawait is only valid in async functions and the top level bodies of modules
يعني ايه
استخدمت await جوه function مش async.
ليه بيحصل
- نسيت كلمة
asyncقبل الـfunction (أو قبل الـarrow).
إزاي تصلّحه
- اكتب
async function(أوasync () =>).
جرّبناه فعلًا
function load() {
const r = await Promise.resolve(1);
return r;
}async function load() {
const r = await Promise.resolve(1);
return r;
}
load().then(console.log);1الدروس اللي بتشرحهغير المتزامن: Promises و async/await