I can retype the code but what exactly is it doing?


What exactly is this doing? Pushing the object properties into the array?

definition of a Bird constructor

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

creating an instance of Bird called canary. Being an instance of Bird (Bird is the blueprint used to create canary, you might say), canary will have the name and numLegs properties.

let canary = new Bird("Tweety");

an array to put stuff in

let ownProps = [];

This for in statement will visit each property in canary and do something to it that we define

for (let property in canary) {

. canary has two properties that it got from Bird

  if(canary.hasOwnProperty(property)) {

we use hasOwnProperty (pedantically called Object.prototype.hasOwnProperty()) to test each property of canary to see if it is a property of canary. Which is kind of silly, if you think about it. Since by running through the for in expression, we know that it’s a property of canary. But go with it…


If the preceding line evaluates to true (that is, if the result of calling hasOwnProperty puts out true), then add that property to the array we made earlier. Kind of our “results” array.