Prefix field names with # to make them private. Private fields can only be accessed inside the class.
class BankAccount {
#balance = 0;
deposit(amount) {
this.#balance += amount;
}
getBalance() {
return this.#balance;
}
}
Outside code cannot access #balance directly.