25. Private Method


Can any one explain more clearly on this below code especially these lines
var myBalanceMethod = john.askTeller();
var myBalance = myBalanceMethod();
I hope myBalanceMethod is not a method but, why we used parentheses for it.


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.


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