The following function Phone() creates a prototype and Phone.prototype.screenSize = 6; adds the screenSize property
function Phone() {
this.operatingSystem = 'Android';
}
Phone.prototype.screenSize = 6;
then if we made a new object myPhone and checked if it contains the screenSize property it returns false although the property was added before creating the object.
const myPhone = new Phone();
const inherited = myPhone.hasOwnProperty('screenSize');
console.log(inherited);
// false
Why doesn't it return true and how to make it return true
hasOwnPropertychecks the object and explicitly not the prototype chain.hasOwnPropertyreturns true? Then you need to attach the property to the instance. Do you want to verify the property exists? Then usein. This seems a bit like an XY problemscreenSizebecame part of the chain just likeoperatingSystem? @VLAZ