I created a JavaScript object like this:
var obj = {
a: 10,
b: 20,
add: function(){
return this.a + this.b;
}
};
I executed the function as obj.add
and it returns the whole function as string a like this:
function(){
return this.a + this.b;
}
But later, I tried to call the function again, including the parentheses, like `obj.add()` and it returns the value `30`. I couldn’t figure out why I get such a different output upon calling the function with `obj.add` and with `obj.add()`. What is the main difference between calling an object’s function with parentheses and without parentheses?