Syntax help

I’ve been struggling to understand “Promises” at the moment. The first (and really basic) problem I ran into is the syntax of certain functions. They use “extra” parenthesis before the curly braces, here is an example:

const promise = new Promise((resolve, reject) => {  <------- this first parenthesis, can someone explain?
  setTimeout(() => {
    resolve('*');
  }, 1000);
});
 .......

So the question is, usually we have the syntax const functionName = () => { ...... } so why are we now using that extra parenthesis again? I know I’ve seen it before but I just can’t remember where and I can’t find out the reason for it (hence the topic here…)

Thank you very much!!!

The Promise constructor takes a callback function, which is everything inside the parens.

new Promise(...)
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.