5.5 Constructor Properties

Every object in JavaScript has a property called a constructor. And this refers to the function that was used to construct or create that object. So here we have two objects circle and otherCircle. Let's look at their constructor property. So, here, on the console, we're going to write otherCircle dot constructor. So, as you can see, this returns our circle function that we used to create this object. Now let's look at the circle. constructor. So what is it? Well, we can say it's a function, because here we have this f in blue. And as you can see, the first letter of this function is capitalized. So this is a built-in constructor function in JavaScript, when we create an object using the object literal syntax, internally, the JavaScript engine uses this constructor function. Let me explain this in detail. So I'm going to temporarily remove all this code. We'll define an object like this, when we use this syntax, object literal, the JavaScript engine will translate it to something like this. Let x equal new object. So the circle object that we created and returned from our function factory, and because we used the object literal syntax. Internally, it was created using this object constructor function. In JavaScript, we have some other built-in constructors, for example, we have a string to create strings, but quite often we use string literals. So single, or double, or backward dimensions. Using these literals is cleaner and easier than using the constructor. We also have a boolean, but again, we don't use that, we use either true or false. So we call them Boolean literals. We also have numbers, but instead we use numeric values, . So here's what I want you to remember, each object has a constructor property, and that refers to a function that was used to create that object. That's it for this little video on constructor properties, we'll see you in a very next video.