Below I have attached an excerpt from the chapter 10 of Eloquent JavaScript book.
var dayName = function () {
var names = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
];
return function (number) {
return names[number];
};
}(); //==> '();' this construct right here....
console.log(dayName(3));
What I cannot understand is why this function has a trailing ();?
What is it's use? I have tried finding the answer but I don't know what to look for.
Can anybody explain me why this construct is added in the end? Any help would be invaluable.