Consider the constructor function below
function Person(first, last, age){
this.name = {
first,
last
};
this.age = age;
};
Now we create an object with the above constructor function
var person1 = new Person('Bob', 'Smith',32);
Now if we do console.log(person1.name) we get following output in the console
{ first: 'Bob', last: 'Smith' }
I would like to know how this happen, that it's able to create key as first and value as Bob and similarly with last.Also, same output is logged if we change the this.name property in the constructor as follows
this.name = {
first:first,
last:last
};