The use of "for" loop with hasOwnProperty method

unnecessary code in the material?
the code i used is:

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

let canary = new Bird("Tweety");
let ownProps = [];
// Only change code below this line
for (let property in canary) {

the code used in the learning material:

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

why add the if statement?

Challenge: Understand Own Properties

Link to the challenge:

Just found the answer.
It’s there for the “prototype” thing :slight_smile:

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