24. accesing private variables, one question


Hello, i had no problems to finish the exercise but i have a few questions about, this is my code, working ok:

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

this.getBalance = function() {
// your code should return the bankBalance
return bankBalance;

var john = new Person('John','Smith',30);

var myBalance = john.getBalance();

And this is my question, instead of writing a new variable that hold the balance ( var myBalance = john.getBalance() ), why dont print the balance directly with john.getBalance() ? .
Is this another correct form to reveal the balance but the exercise is programmed to work only between his parameters or am i wrong?

Replace this line with your code.


The getBalance() Method will return a Value with NoDisplay.

So either you use
console.log( john.getBalance() );
or via two-steps
var myBalance = john.getBalance();