23. private Variables


#1

I do not understand why it passes..its not making any sense. Cause my output is not relevant

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

Start next new lesson.

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","Sauls",21) 
console.log(john.bankbalance);

// try to print his bankBalance

#2

HI you try to access a private variable so it normal that you get that output on next lesson they wil teach you how to access it .


#3

Hello @devninja93146,

The reason this exercise exists is to show you that in javascript, inside object constructors, you can make "private" variables that cannot be accessed by the rest of the code...


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.