In the code in question you can see the work with prototypes and objects, the following code can be more obvious:
function Human() {} Human.prototype.val = 5; var man = new Human(); console.log(man.hasOwnProperty('val')); man.val++; console.log(man.hasOwnProperty('val'));
As you can see from the output: before executing the ++ property, the val property itself is missing in the man object, and after execution it is present.
Why it happens?
When trying to get the property value, if there is no such property = the property of the same name in the prototype of the object will be checked until it is found, or until the prototypes run out.
In case of assigning (changing) the value of a property, if it is absent in the object - it (in most cases) will be added to it.
Since .val++ first gets the value, it is taken from the prototype.
Further, it is increased and stored directly in the object. Therefore, subsequent changes in the value in the prototype do not affect the output of .val since the property begins to be taken directly from the object, and it does not reach the verification of the prototype.