25. Private Method


#1

Can any one explain more clearly on this below code especially these lines
var myBalanceMethod = john.askTeller();
var myBalance = myBalanceMethod();
console.log(myBalance);
I hope myBalanceMethod is not a method but, why we used parentheses for it.
https://www.codecademy.com/en/courses/objects-ii/4/4?curriculum_id=506324b3a7dffd00020bf661


#2

They're assigning the value of john.askTeller to a variable called myBalanceMethod. Then they're assigning that variable to a variable called myBalance. So basically when you read var myBalance = myBalanceMethod(); you're really reading var myBalance = john.askTeller(); Then they're using console.log to print the value of the variable myBalance (which is the value of john.askTeller).

I am assuming that when you set a variable equal to a method, that variable itself becomes a method, thus using parentheses after myBalanceMethod.

Hope this helps! I had to read the code through a few times myself haha.


#3

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