I created a JavaScript object like this:
var obj = {
a: 10,
b: 20,
add: function(){
return this.a + this.b;
}
};
I executed the
You must use () to call a function in JavaScript.
If you do not use parenthesis, you are simply referencing the function, which can be useful in a case where you would like to pass a function to another code block for deferred execution.
In your situation, because you wish to call add right away, you should be sure to use ()
obj.add();