23. Private Variables


#1

https://www.codecademy.com/en/courses/objects-ii/4/2?curriculum_id=506324b3a7dffd00020bf661

So, i passed this exercise, but the result is 'undefined'. Am i missing something or what? Any help would be useful. :smiley:

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
}

// create your Person 
var john = new Person('John','Smith',30);
var bankBalance = john.bankBalance;
// try to print his bankBalance
console.log(bankBalance);

#2

Yea, you are suppose to get undefined since bankBalance is private. You could have either reached this conclusion by reading the information of the exercise, or move on to the next exercise where this is explained in even more detail


#3

Stupid me, thanks for such a fast response. :slight_smile:


#4