I am in confusion


#1


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


Actually i want to know that,why in this exercise where we are making our askTeller function curly braces are not included with "if else" and also "return" is used in the same line with "if else".Because we are learning to use curly braces with "if else" from the beginning of this course it is necessary to ask here.Is it optional to use?
Also i want to know about "==" and "===" because in the first chapter of this course it is said that "===" means equal to,but here "==" is used for equal to. do they work same?

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);
console.log(myBalance);


#2

For the first question, I don't think you need to use your curly brackets in this case as you are using if and else if statements inside a function.

For the second question, when you use == you check if something is equal to something else. This is not strict. When you use === you check if something is equal to something else. This is strict. What strict does, is checks not just the equality of the two values, but also it compares the types of the two values too.

If you need further explanation let me know.
However If this helped your understanding please mark my reply as the solution.


#3

ok i got it but can you give me an example of where to use "==" and where to use "==="


#4

I'm not sure off the top of my head a good example to give you. But here is a simple one.

console.log(true == '1'); // true
 
console.log(true === '1'); // false

#5

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