Passing Arguments /if else


#1



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


for askTeller function there is an if else function but is structured differently. Is this only for when in class or can you use this new form anywhere else?

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
  
   this.askTeller = function(pass) {
     if (pass == 1234) return bankBalance;
     else return "Wrong password.";
   };
}

var john = new Person('John','Smith',30);
/* the variable myBalance should access askTeller()
   with a password as an argument  */
var myBalance = john.askTeller(1234);


#2

We are allowed to not use code blocks for single line actions.

if () // code only on this line
else // code only on this line

In both cases above they are simple return statements. Play with this on your own and see what you may and may not do in JavaScript without invoking a code block.


#3

No the if/else block does not necessarily need an opening and closing brace {} if you have just one statement in each block. But if you have more than one then you have to add the braces