When you create an object of type person and set the name property as "bb", it causes confusion because in the function you attempt to alert the sayname which is not a property, but rather a function.
Here's a more detailed explanation:
Essentially, the function defined here serves as a factory for creating objects with specific properties and methods.
function Person(){}
Person.prototype.name="aa";
Person.prototype.sayName=function(){
alert(this.name);
}
After defining the function, you proceed to create an instance of this object type using the following code:
var per = new Person();
You have the ability to overwrite the default property or call the method using the instance `per` like so:
per.name = "bb";
The above code changes the property name to "bb". Therefore, when calling the sayName method, it will output "bb" as expected:
per.sayName();
When the sayName function is executed, the alert displays "bb" because 'this' refers to the current object instance, and then retrieves the value of the property.name