Enumeration through Object

//Hi there

//We can enumerate through an object using for in loop

//For Example

const circle2 = {

radius: 10,

draw() {

console.log("draw");

},

};

//For enumeration, we will use for in loop

for (let key in circle2) {

console.log(key, circle2[key]);

}

//We will get the results of properties and their values on the console.

//But how can we enumerate when we define and object using constructor function ?

//Like this.

function Circle2(radius) {

this.radius = radius;

this.draw = function () {

console.log("draw");

};

}

//For in loop is not working here so plz tell me how to enumerate this ?

I have find the answer here that when creating an object using the object literal syntax i.e. without using factory and constructor functions. for in loop is directly accessible to the object.
So as the object is directly created using object literal we can use for in loop.
While defining and object with factory or constructor, we need to first create an instance of the object then we will enumerate through that instance of the object that we created. :slight_smile: