# Explain Closures!

Hey there, so I was working on the Arguments Optional challenge here. I solved the problem, but I don’t quite understand how the closures function works that I wrote. Here is the function that I made that I could use some advice on to understand what is going on. Specifically, I am confused about how the second number works when it is added on to the end of the function being called.

``````var args = Array.prototype.slice.call(arguments);
return function(y) {
if (!Number.isInteger(y)) {
return undefined;
}
return x + y;
};
};
}
``````

You did not copy/paste your entire function.

Here it is:

``````function addTogether() {
var args = Array.prototype.slice.call(arguments);
return function(y) {
if (!Number.isInteger(y)) {
return undefined;
}
return x + y;
};
};
}
``````

When I run your code, I get the following error, so not sure how you solved the problem with this solution :

``````TypeError: addTogether(...) is not a function
``````

Also, args is not used anywhere else in your function that I can see.

``````var args = Array.prototype.slice.call(arguments);
``````

Sorry, I copied part of it out of a larger piece of code because it was only one piece that I had a question about. I’ll put the whole thing in.

``````function addTogether() {
var args = Array.prototype.slice.call(arguments);

var isNumb = function Numb(args) {
for (i = 0; i < args.length; i ++) {
if (!Number.isInteger(args[i])) {
return undefined;
}
}
return true;
};

return function(y) {
if (!Number.isInteger(y)) {
return undefined;
}
return x + y;
};
};

return a + b;
};

if (!isNumb(args)) {
return;
} else if (args.length === 1) {
} else if (args.length > 1) {
}
}

``````

HI.

If I’ve missed some subtle point about what you’re trying to achieve, I apologise, but…

return (function plus(b) {
return a + b
})
}

console.log(result)

will give you a function that employs a ‘closure’.

If you call it like this, it’s easier to see what’s going on

return (function plus(b) {
return a + b
})
}