Private Methods


#1



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


In the instructions it states:"Because askTeller returns a method, we need to call it to make it any use. This is what var myBalance = myBalanceMethod(); does."

So instead of the last two lines why can't it be console.log(myBalanceMethod()); Both ways print out the same output so why use the lower one over the other. Is there a benefit in using the one below.


function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
  
   var returnBalance = function() {
      return bankBalance;
   };
       
   // create the new function here
   this.askTeller = function(){
       return returnBalance;
       };
}

var john = new Person('John','Smith',30);
console.log(john.returnBalance);
var myBalanceMethod = john.askTeller();
var myBalance = myBalanceMethod();
console.log(myBalance);


#2

you can do that too.Because askTeller returns a method, we need to call it to make it any use and you have called here :slight_smile:

console.log(myBalanceMethod());