Make a Person, difference in Object.keys

Make a Person, difference in Object.keys
0

#1

Tell us what’s happening:

why my code shown below works well except Object.keys(bob).length returns 7.
However, if I replace this.firstAndLast with fullName, it works perfectly (Object.keys(bob).length returns 6).
Can anyone explain this difference. It seems work in Java.

Your code so far

var Person = function(firstAndLast) {
    // Complete the method below and implement the others similarly
 this.firstAndLast = firstAndLast;
  
 // define getter and setter 
 this.getFullName = function() {
      return this.firstAndLast;
    };
  this.setFullName = function(firstAndLast){
      this.firstAndLast = firstAndLast;
    };
  
  this.getFirstName = function() {
      return this.firstAndLast.split(" ")[0];
    };
  this.setFirstName = function(firstName){
       this.firstAndLast = firstName + " " + this.firstAndLast.split(" ")[1];
    };
  
  this.getLastName = function() {
      return this.firstAndLast.split(" ")[1];
    };
  this.setLastName = function(lastName){
     this.firstAndLast = this.firstAndLast.split(" ")[0] + " " + lastName;
  };

};

var bob = new Person("Bob Ross");
bob.getFullName();

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36.

Link to the challenge:


#2

Each this.something is a property (object key), so with the this.firstAndLast, you will see 7 for Object.keys(bob).length and 6, if you replace it with fullName. fullName is a local variable to the Person function and not an object property.