In this code isn't the numLegs defined in the constructor and not the instance of the object? Thus making it not an Own Property of duck?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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

let duck = new Bird("Donald");
let canary = new Bird("Tweety");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.177

Challenge: Understand Own Properties

Link to the challenge:

Nevermind I get it…It is because of the this keyword which refers to the newly created object

Now ‘numLegs’ is an own property of duck;

1 Like

The constructor is just the function that creates the object, eg the point of new Bird("Donald") is to create an instance of Bird like { name: "Donald", numLegs: 2 }

1 Like

Thanks for replies guys. I get it.

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