Consider the following code, which awaits a Promise:
async function handleSubmit() { try { await submitForm(answer); } catch (err) { console.log('Error') }}function submitForm(answer) { return new Promise((resolve, reject) => { setTimeout(() => { if (answer !== 'OK') { reject(new Error('Rejected')); } else { resolve(); } }, 1500); });}
Note that I never explicitly passed resolve
/reject
to the Promise, yet they are being passed (breakpoint in any JS console to see for yourselves). So my questions are:
- Who passes the parameters to the Promises' anonymous function? It is the
await
construct? - What exactly gets passed?