I created a JavaScript object like this:
var obj = {
a: 10,
b: 20,
add: function(){
return this.a + this.b;
}
};
I executed the
Calling a function requires the () because they are the function invocation operator. To execute a function you will always need to include parentheses.
When you call ambes.add
you are returning the function object itself. If you do so inside console.log()
or concatenate it onto a string JavaScript will return the function definition as a complete string which explains the first output you receive.