DEV Community

Discussion on: Closures - JavaScript Concepts

Collapse
 
monfernape profile image
Usman Khalil • Edited

I read something like this in a random code: something ()(). What do two parenthesis represent?

Collapse
 
boywithsilverwings profile image
Agney Menon

I was not comfortable with this syntax the first time I learnt this and hence even though it makes sense now, I still write it in two different lines so it would be easier for everyone reading.

const intermediateFn = something(); // something returns a function
const result = intermediateFn();  // calling the fn returned from something

If you are familiar with React, this syntax is what is used with Redux connect or Apollo's graphql.

Collapse
 
jlitowitz profile image
Jason Litowitz

In this case, assuming the function something returns a function, the first set of parenthesis will execute the something function, just like normal; the second set of parentheses will then execute the function that something returned.

Collapse
 
monfernape profile image
Usman Khalil

I really appreciate your response. Thank you for making these hardcore concepts easy to digest