Why is there an extra "(" after the promise?

Tell us what’s happening:
Describe your issue in detail here.
I am very stingy about my learning and I always want to know the reasoning behind things. I can not understand why there is an ( after the promise and why it goes all the way to the ; as I have never seen a ) go past the function from the arguments.

Your code so far

const makeServerRequest = new Promise((resolve, reject) => {

});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Create a JavaScript Promise

Link to the challenge:

The Promise constructor takes a callback function as a parameter.

The callback function is this bit:

(resolve, reject) => {

}

It’s standard arrow function syntax.

Check out the “Basic syntax” section:

Multiple params require parentheses

My question is more around the last parentheses.
(resolve, reject) => {

}
this looks standard, however
((resolve, reject) => {

});
^
this is where my question arises

I forgot to reply to you in the previous response.

const makeServerRequest = new Promise((resolve, reject) => {

});

is similar to:

const myCallback = (resolve, reject) => {

};
const makeServerRequest = new Promise(myCallback);

the last ) your asking about is actually the closing ) of the Promise constructor.

However, if you noticed with the last example, using myCallback is redundant and not as clear as if you pass the function in directly as an argument.

1 Like