The correct selections are C and D because both declare a function as a property of an object, which is the defining characteristic of a JavaScript method. MDN describes a method as a function associated with an object, or more specifically, an object property whose value is a function. In option C, Score: function() { ... } is object-literal syntax. It defines a property named Score whose value is an executable function, so that property behaves as a method of the object. In option D, this.Score = function() { ... } assigns a function to the Score property of the current object instance. MDN notes that this is commonly used inside object methods to refer to the object the method is attached to. Option B does not declare a method; it calls Score() and assigns the return value. Option A is only an incomplete or ordinary variable declaration and does not create a function-valued object property. References/topics: JavaScript objects, custom classes, methods, function expressions, this.
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