Kindly explain working of function 'printPersonName' in the code.I am not clear with how this function works?


function Person(name, age) { = name;
    this.age = age;
// a function that prints the name of any given person
var printPersonName = function(p) {

var bob = new Person("Bob Smith", 30);

// make a person called me with your name and age
// then use printPersonName to print your name
var me = new Person("Anushree", 28);


when you call the function:


you pass as argument bob (bob is your newly created object), now inside your function the object is stored in the variable p, the function parameter:

var printPersonName = function(p)

so now will log the name, p would have list the entire object, p.age would have logged the age


Is this '' similar to '' ?Like in previous exercises when we want to access a property we used


p is the function parameter, it holds the argument (bob) you passed into the function when calling the function. So yes, they are the same. If you don't know how function arguments/parameters works, you might want to find the exercise which explains this


Thanks a lot :slight_smile: I was a bit confused about the arguments..but now I am clear with it.