I am creating a javascript object as below code:
var obj={ a : 10, b : 20, add : function(){ return this.a + this.b; }, };
i executed this function using this code obj.add and returned the entire function as a string: -
function(){ return this.a + this.b;
but later I will try to call the function again, including brackets like obj.add() , and it will return 30. Here, I canβt understand why I get such a different call by calling the function with obj.add and obj.add() ? What is the main difference between calling a function of objects with parentheses and the absence of parentheses. Can any body help?
source share