I had a little understanding of closure which, a function that can be stored as a variable (referred to as a "first-class function"), that has a special ability to access other variables local to the scope it was created in.
Somehow I had trouble how this code works, how does these independent functions messageForRahul/Greg gets executed inside the Inner function when they are not declared as a parameter?
var sendMessageTo = function (name) {
return function (message) {
console.log ("Message for " + name + ": " + message);
}
};
var messageForRahul = sendMessageTo ("Rahul");
var messageForGreg = sendMessageTo ("Greg");
messageForRahul ("Hello, Rahul");
messageForGreg ("Hello, Greg");