Understand Own Properties - question

Hi, can someone please clarify why is the if(duck.hasOwnProperty(property)) necessary in the below example if we can just iterate over all properties with for (let property in duck) {ownProps.push(property)}?

function Bird(name) {
  this.name = name;
  this.numLegs = 2;
}

let duck = new Bird("Donald");

let ownProps = [];

for (let property in duck) {
  if(duck.hasOwnProperty(property))  {
    ownProps.push(property);
  }
}

Hey @camperextraordinaire!

I’ve just passed this lesson and it all really sunk in. My only issue is I don’t understand how it actually checks the object for the property. Will it check for all properties or for those passed into (property), or is it just that it has been declared and it checks if the declared (let property) is an own property of duck?

Thanks in advance!

Haha! Funny enough I did, and now understand the code!