Just wondering, having the following simple code:
var object1 = {
name: function (){
return 'myName';
},
surname: function (){
return 'mySurname';
}
};
Why does JS returns function() in this case object1.name ?
Why does JS returns the expected result myName if I call object1.name() ?
namereturns whatnameis–in this case, a function.nameby appending(), i.e.,name(), returns a value–the string"myName".My answer to When do I use parenthesis and when do I not? provides more details.