Why is the return statement not implied in a getter?

Hello there! I’ve recently started Learn Intermediate Javascript, and I’ve wondered just why we need to type return when we use a getter.

In other words, why do we need to write this:

class Surgeon {
  constructor(name, department) {
    this._name = name;
    this._department = department;
    this._remainingVacationDays = 20;
  }
  get name() {
    return this._name;
  }
  get department() {
    return this._department;
  }
  get remainingVacationDays() {
    return this._remainingVacationDays;
  }
}

And not this:

class Surgeon {
  constructor(name, department) {
    this._name = name;
    this._department = department;
    this._remainingVacationDays = 20;
  }
  get name() {
    this._name;
  }
  get department() {
    this._department;
  } // Or this:
  get remainingVacationDays() { this._remainingVacationDays; }
}

Are there any situations in which you don’t want to return a value? I had expected it to be more like arrow function expressions, in which you don’t always have to type return.

Thanks in advance.
Zoetje.

In this very basic example, your getter is literally just doing one thing to get the value. What if it needs to do something even slightly fancier?

Here’s a basic example in which an interpreter would not know what to “get” if it didn’t have it explicitly stated.

class Rectangle {
  constructor(length, height) {
    this._length = length;
    this._height = height;
  }
  get area() {
    return this._length * this._height;
  }
}

That’s true. Thanks!