Iterating through a property question

So my question is this.
I know this is the syntax for(prop in obj), but does the computer recognize the properties because of the constructor?
so the computer sees the curly braces {} knows it’s an object and hence it knows its a property and not just a random variable?

  **Your code so far**

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

let canary = new Bird("Tweety");
let ownProps = [];
// Only change code below this line
for (let property in canary) {
if(canary.hasOwnProperty(property)) {
  ownProps.push(property);
}
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36

Challenge: Understand Own Properties

Link to the challenge:

The own properties on Bird are created by doing the following two things:

  • Adding them to this in the function.
  • Calling the function with the new keyword.

You must do both of these in order to make these own properties of Bird. If you do then that’s how JS knows that they are own properties.

1 Like

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