When exactly should you prepend the underscore when accessing the property of an object with this keyword

In this lesson/project, when I solved the project, I used the underscore (_) character to prepend the property names, eg, (_players) and (_games), while accessing them with this keyword in the code and it worked.

However, in the walk through video, the instructor didn’t prepend the property name with underscore character and it also worked.

So, When exactly should you prepend the underscore character when accessing the property of an object with this keyword and when should you not?

Thanks

The underscore is just a (naming) convention for properties that implement a getter (and/or setter)

I mean, we could also do:

const myObj = {
   a: 3,
   get getA()
   {
      return this.a;
   }
}

console.log(myObj.getA);

The biggest flaw with this approach, is that we don’t know the property implements a getter. Which means someone else working on your code might be tempted to access the property directly, bypassing your getter logic

Ideally, when you implement a getter for a property, always use the getter. Don’t access the property directly. Of course it would help if JS has implemented proper encapsulation in my opinion)

one final piece of advise: always program defensive.