Last updated on July 13th, 2020 at 01:30 pm.
Hi, and welcome back.
So I’ve also come across this about objects and I want to talk about this one.
In one of the last videos, I said that when you’re declaring a ‘const’, you cannot use the same identifier for another variable within the same block.
And it’s the same thing for an object name.
You cannot declare an object name.
We’re going to look at ‘objects’ and ‘functions’ later on.
So it says that object attributes are not protected.
So the following statement is executed without problems.
Object attributes, these are the object attributes.
This is the object attribute, the key and the value pairs.
So let me copy this and just bring it to Scratchpad.
I will remove these two and paste in what I have within this block.
So ‘const’, if I declare an object as a constant and I give it the name ‘MY_OBJECT’ and it has a key and a value.
If I point to whatever is here, I can give it a different value, which we know should not be true for an object.
We cannot change the value, we cannot change that value directly like this.
So this would be like redeclaring this.
So basically what that statement meant was that the ‘const’ does not protect the attributes.
So let’s say, I have this, ‘MY_OBJECT’.
Let’s say maybe it’s a graduation list, right.
And you have a name.
So ‘name’ and then the name is ‘Ricky W’.
And then, I want to change ‘MY_OBJECT.name’.
So, I want to change it to something like ‘Victor W’.
And then, I want to alert the value.
We’ll look at ‘objects’ later on.
So if you don’t understand about this object things, don’t worry.
I’m just using it as an example.
So if I come here and alert the value of the object, and I run this, it tells us that the value for that is ‘Victor W’ even though our variable, our constant was declared with this one.
So I just thought that’s something I should tell you about, even though we’re going to look at objects later on.
And once you understand more about objects, you’ll be able to understand where you can use it.
Somewhere I can see this useful is, let’s say this is a graduation list.
Maybe you don’t want people or you don’t want this list to be tampered with.
Maybe that’s a scenario where you can use the ‘const’.
So that’s it for this video.
I will see you next time.
See you in the next video.
Recommended VPS Providers
Find out the VPS providers I recommend.