25/30 Why leave out the parentheses?


#1

I do not understand why the parentheses should not be used after returnBalance. The code would be shorter and simpler to understand if the parentheses were added. The bankBalance could be called in one sentence in that case. Both cases result in the same output, although only the version without parentheses after returnBalance is approved by Codecademy.

I am probably missing something since I'm pretty new to programming. Could you please explain it to me?

This is my (approved) code:

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);
// console.log(john.askTeller());
var myBalanceMethod = john.askTeller();
// var myBalance = myBalanceMethod();
console.log(myBalanceMethod());

#2

bankBalance is is a variable not if it were a (that takes no arguments) then writing bankBalance() would be correct


#3

I don't even get that which parentheses they are talking about!!! I got it right but haven't feel anywhere that i should not put a parentheses..

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);