While trying to understand closures in JS,I came across the following code:
var add = function () {
var name = "xyz";
return function ()
{
return name;
}
}
();
I am unable to understand the purpose of () at the end of the function.
Using console.log(add());
gives xyz
as the output.
But when I remove the () from the end of the function, I am getting [Function]
as the output.