1D0-720 · Question #5
Which statement is true regarding methods in JavaScript?
The correct answer is A. Methods are functions stored as object properties. Option A is correct because in JavaScript, a method is simply a function that has been assigned as a property of an object - when you call obj.greet(), greet is a method because it's a function living inside obj. Why the distractors are wrong: B is the opposite of true - the…
Question
Which statement is true regarding methods in JavaScript?
Options
- AMethods are functions stored as object properties.
- BMethods cannot be called on objects.
- CMethods are the same as JavaScript loops.
- DMethods are used to link JavaScript to HTML.
How the community answered
(20 responses)- A90% (18)
- B5% (1)
- C5% (1)
Explanation
Option A is correct because in JavaScript, a method is simply a function that has been assigned as a property of an object - when you call obj.greet(), greet is a method because it's a function living inside obj.
Why the distractors are wrong:
- B is the opposite of true - the entire point of methods is that they are called on objects (e.g.,
array.push(),string.toUpperCase()). - C confuses methods with loops (
for,while), which are control-flow constructs, not object properties. - D describes
<script>tags or event attributes - the mechanism for linking JS to HTML - which has nothing to do with methods.
Memory tip: Think of a method as an object's action - just as an object has properties (data it has), it has methods (things it does). If a function belongs to an object, it's a method.
Topics
Community Discussion
No community discussion yet for this question.