5.4 Dynamiquc of Objects
One thing we need to understand about objects in JavaScript is that they are dynamic, which means that once you create them, you can always add new properties or methods, or remove existing ones. So here we have a circle object with only one property which is radius, we can add another property like color and set it to yellow, when we save the circle to the console you can see that we have two properties, color and radius. Similarly, we can add a new method here, so circle point draw, we set it to a new function and now when we connect it to the console, we can see that our circle object has three members, two properties, color and radius and one method. We can also delete existing properties or methods, so here before we save the circle, we can use the delete operator, to delete a member of a circle object. This member can be a property method. So we make a circle dot color, we can also delete the draw method, so circle. Draw, now save the changes, we can see that our circle object only has the radius property that we added when we created this object. Now, one thing that some developers find confusing is that here we have used the keyword const, to define a new constant. However, you can see that I modified the circle object property and then deleted this property. So what kind of constant is this? Well, when we use a constant here, it means that we cannot reassign this variable, so this variable is more precisely a constant. So we can't reset the circle to a new object. If we do that, we get this error. So assignment to a constant variable. So we can't reassign that constant, but we can still modify the circle object by adding or removing properties. That's it for this video on the dynamic nature of objects in JavaScript, let's meet again for a very next video.