JS Understanding of function calls

Tell us what’s happening:
I don’t get what haeppens when a functions without parameters is called in a specific way. Like here in the calls 2 and 4. If I console.log(arguments) I get the message with addTogether(…) is not a function. What does especially these two calls are trying to do?

addTogether(5)(7);
addTogether(2)([3]);

Your code so far


function addTogether() {
console.log(arguments)
return false;
}

addTogether(2,3);
addTogether(5)(7);
addTogether("http://bit.ly/IqT6zt");
addTogether(2)([3]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Arguments Optional

Link to the challenge:

addTogether(5)(7) implies a currying function.
Currying functions are declared a bit different then regular functions, and they are a feature that came with ES2016.

const addTogether = (x)=>(y) =>x+y

for instance can be called like this:
addTogether(5)(2);
to get a result of 7.

Here is more info about them:

1 Like