Private properties
by REPLY2SAGAR
JavaScript
class Person {
#name;
constructor(name) {
this.#name = name;
}
getName() {
return this.#name;
}
}
let bob = new Person("Bob");
console.log(bob.getName()); // Outputs: Bob
// console.log(bob.#name); // This will throw an error