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; },
};

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.

Further reading

Problem with a question

JavaScript · Middle · question 48

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz