To call the sayHello method in the given JavaScript object, you need to use the object's name followed by the method name with parentheses.
Correct Method Call:
Given the object definition:
var obj = {
sayHello: function() {
alert("Hello");
}
};
To call the method sayHello on the object obj:
obj.sayHello();
Explanation:
Option A: Obj.sayHello; is incorrect syntax. The correct syntax is obj.sayHello();.
Option B: Window.sayHello(); is incorrect because the method is defined in the obj object, not the window object.
References:
MDN Web Docs - Functions
W3Schools - JavaScript Objects
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit