Passing private variable in JavaScript nested class?
Teams have members, so it almost seems natural to put the Member class into the Team class. But projects also have members. How are you going to implement that? You can't nest Member in both classes. Another problem with nested classes is that you have to traverse through Company -> Department -> Team -> Employee hierarchy just to get everyone's name or email.

Answering your question, how can you pass some variable that can't change outside of the class. Create a getter method:

function Team() {
    var teamId = 4; // not changeable from outside
    this.getId = function() {
        return teamId;
    }
}


Now you can access teamId from outside of the class, but can't change it.

Or instead of creating truly private properties and functions, you can simply prefix them with an underscore to denote they are private and should never be accessed from outside. While nothing really stops you from accessing them, nothing also stops you from redefining the Team class and accessing anything you want.