Benefits of using a getter?

In the example below, i get the same results if i log “_key1” directly, or if i log it through the getter.
Why do I need the getter for? is it only for privacy of the key?

const object {
_key1: value1,
_key2: value2,
get key1 () {
  return this._key1
};

console.log(object._key1);
console.log(object.key1);

It’s a convention to communicate (to other people) that the value being set or get should not be interacted with directly, but rather only through setters, getters, and any other functions or methods which interact with that value.

2 Likes