28 & 29


#1

Right, so I'm a tad confused about the person1 and person2 bit. From the code below, there is no other mention of person1 and person2 linked to alice and billy, so how does the programme know person1 and person2 is part of the Person constructor? What I mean is, how comes we add 1 & 2 next to person and the programme knows it is still part of the Person stuff?
And also, why isn't person1 written as Person1? That would probably make more sense to me.

Hopefully that makes sense.

function Person (name, age) {
    this.name = name;
    this.age = age;
}

var ageDifference = function(person1, person2) {
    return person1.age - person2.age;
};

var olderAge = function(person1, person2) {
 if (person1.age > person2.age){
     return person1.age;
     }
else {
    return person2.age;
}
};

var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);
var diff = ageDifference(alice, billy); {
    console.log("The age difference is " + diff);
    }
console.log("The older person is " + olderAge(alice, billy));

#2

Oh I think I know, it's because we have defined person1 and person2 via var diff and console.log on the last line, right?


#3

Hi i, person1 and person2 are just arguments...

var a = 2;
var b = 3;
var Sum = function(num1, num2) {
    return num1 + num2
};

#here call the function with a and b
Sum(a,b)
#Output 
5

in this case we have has argument num1 and num2