Object Oriented Programming - Iterate Over All Properties

I find this code confusing-

let ownProps = [];
let prototypeProps = [];

for (let property in duck) {
  if(duck.hasOwnProperty(property)) {
  } else {

It is said that console.log(ownProps) would
display ["name"] in the console,
and console.log(prototypeProps)
would display ["numLegs"].
As far as I know, if the first statement is
true, the statement under else do not run. Here
the first statement is true because duck
instance will automatically have its own
property because it is an instance of Bird,
so console.log(ownProps) will display [name]
but why statement under else is also executed? when it should not be.
Can you please clarify?

Is this a challenge? please post the link or instructions so we can better assist you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.