Quantcast
Channel: User bavaza - Stack Overflow
Viewing all articles
Browse latest Browse all 45

What functions are passed to the Promise when awaiting in javascript?

$
0
0

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:

  1. Who passes the parameters to the Promises' anonymous function? It is the await construct?
  2. What exactly gets passed?

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>