JavaScript · Middle · Question 48 of 75
How does a getter differ from a regular property?
const user = {
first: "Ann", last: "Lee",
get full() { return this.first + " " + this.last; },
};- ✓Correct answer: The value is computed on every
user.fullaccess, without call parentheses - 2The value is computed once when the object is created and then cached
- 3A getter can only be called as a method:
user.full()
Explanation
A getter looks like a property but runs a function. Without a setter, assigning user.full = ... is ignored (an error in strict mode). Getters are used for computed fields and for validation via a getter/setter pair.