Information Hiding

Let's reiterate that, at the time of writing, JavaScript class syntax does not allow for declaring fields. It is, however, being proposed to do it using a syntax like this:

class Account {
  balance = 0;

  deposit(amount) { 
    this.balance += amount 
  }
}
Transpilers

There are applications (called transpiler), like Babel that allow you write your source code using proposed sysntaxes (such as the one above). You can then transpile your source code to the standard JavaScript. When we use React to build front-end application, it comes packed in with one of these transpilers.

There is no notion of visibility modifier in JavaScript class syntax. You cannot make a property (attribute/method) private. There are, however, ways to mimic this behavior which typically involves clever use of scopes such as closures.

class Account {
  constructor(balance){
    this.getBalance = function() {
      return balance
    }

    this.deposit = function (amount) { 
      balance += amount 
    }
  }
}

const checking = new Account(100);
checking.deposit(20);

console.log(checking.getBalance());
console.log(checking.balance);

There is also a proposal to declare private fields in (future) JavaScript as follows:

class BankAccount {
  #balance = 0;

  deposit(amount) { 
    this.#balance += amount 
  }
}

You may find some programmers employ a convention similar to that in Python which "signals" a property is private by prefixing its name with an underscore.

class BankAccount {
  constructor(balance){
    this._balance = balance;
  }

  deposit(amount) { 
    this._balance += amount 
  }
}

This doesn't protect the property in any way; it merely signals to the outside: "You don't need to know about this property."