0
  var dayName = function() {
  var names = ["Sunday", "Monday", "Tuesday", "Wednesday",
               "Thursday", "Friday", "Saturday"];
  return function(number) {
    return names[number];
  };
}();

console.log(dayName(1));
o/p->Monday

When the same code is executed without the paranthesis'()' at the end in the dayName variable O/P is different..What is the reason?

Gunacelan M
  • 179
  • 2
  • 10
  • when you run `dayName(1)` you are calling the function dayName with the input argument `1`. the result will be returned and printed. where as if you just print `dayName` without the parentheses you are not calling the function but simply printing the variable dayName which is a function. – sbr Oct 27 '17 at 03:48
  • 1
    Well, of course there is a difference between calling a function and not calling it?! – Bergi Oct 27 '17 at 04:00
  • As Bergi said. First you define a function var dayName. It is now merely defined, you didn't do anything with it yet. The parenthesis at the end is then dayName(), which is a function call. – Koenigsberg Oct 27 '17 at 04:53
  • Sorry ,I meant the parenthesis in the function definition assigned to the dayName variable not the function call – Gunacelan M Oct 28 '17 at 09:58

0 Answers0