In this video.
Let's dive in more to explain what this key word mean.
Well, this is advanced topic in JavaScript, but I'm teaching it as basic.
Right, because I'm going to break it down for you to understand.
And again, I'm going to repeat ourself as you move on.
So let me give you the overview of this keyword.
So now moment of truth.
So what is this?
So let me come up here, okay?
We can build something.
So let's say the.
This keyword.
All right.
So what is it?
So in JavaScript this keyword refers to an object.
The first thing bear in mind.
So let me remove the calling here.
One thing in mind is that in JavaScript the this refers to an object.
And then the objects would differ depending on how it is used.
So if you use this key word in an object that this keyword represents the instance of the particular
object that is being operated on.
So remember, we see that we are using this key word here.
So this key words represent what the immediate or the current object this object is being depending
on.
And this key word is depending on the immediate method, which is called object.
Because we have dots after that.
So this is a method, this function, this keyword is referring to.
The gate.
And this object is the one above here.
Do you get it?
That's the first scenario.
And then we can also console.log objects on its own.
So let's just say console.log.
This.
Check it out.
If I save it now, we get something will happen here.
The same.
This key word is representing the global object.
Remember, the global object is the entire object of the browser or even the environment where JavaScript
is being executed, and that is the browser.
You see, we have a bunch of methods we have here.
So this keyword differs depending where it is used.
Because if you look at this, do we have dots before this?
No.
Yes, we have it, but I don't know.
So this one is the same as window object.
If I save this one, you see, I get the same thing.
If I make use of window doors, this meaning we have on to find.
Meaning that the window represents that this key word when is being alone.
For the meantime, don't worry about this logic for now.
So what I'm trying to conclude here is that.
Don't worry myself by understanding details what these kids are referring to right now.
Take it that wherever you see this, the object that is being operated on is this key word.
And if this key word is being used in a global context like this one, it refers to the global object.
And again if you get back to don't manipulation and let's see how we can handle event.
The button that you click on refers to the object that this keyword.
So don't worry about that.
So take away here in this particular video is that understand that whenever we see person an object
that comes after this keyword or refer to the person that particular object to more precise.
So now that we've got this one right, we can also.
I object in a different way than coming down here after the objects.
And then we also add the objects they maintain here.
We can do it, but we also do it in line.
The same thing.
I can add the method in line with the properties inside.
So how can we also do that?
It's pretty simple to do.
All I need is provide, let's say full name here, full name and then semicolon, then my function name.
Remember?
Don't use arrow function.
If we want to have this keyword arrow function, don't bind this keyword.
If a familiar arrow function well, that is why I'm letting you know by following the arrow function.
Don't worry, if you get back to new features in JavaScript, you talk about new features like map for
each arrow, function, destruction and many more.
For the meantime, use normal function, keyword like function and incredibly don't use arrow function.
Otherwise this keyword does not bind.
The arrow function doesn't bind to this keyword.
Take note here.
So the same thing.
I can copy my function here.
What is inside here and then here.
Now I can comment.
This one out is the same.
So if I check for foo name we see that I get full name over here.
So that is it about I mean how we can add custom method on that.
So before we end up this video, let me give you some critical example here or some demo here.
Let's take that where for this object, let's check if the person is titles like let's say false here.
Yeah, for here.
Let's let's say that for this person object.
You want to check or create a function or method to check.
If the person status is false, then we want to delete the admin property.
How can we do it?
Okay, so let's say let's add our function here in line with this one.
Let's say check.
Starters.
Now semicolon then my function name.
Is that and is that?
So let's check.
So if.
This dirt.
Start us.
If.
It's not equal to true.
Or if it's equal to force.
Yes.
If it's equal to force, then we can go ahead and then let's say we won't delete the person.
The person the person is admin delete.
What's the this.
Because I want access to the person's admin here.
So this dot.
Is admin.
So if I save this one now.
Moment of truth.
Let me comment this one out here.
Now, let's check the entire object person.
Do we have?
Is admin inside or is still here?
Because I haven't called a function because having quite a few I still see it's admin here.
I won't delete it.
Right.
So let's call the function down here.
So person dot check check status as a function like this one.
If I save this one now, let's check the person.
Do we see?
It's been here.
It's gone.
Or we can even change the property to, let's say, false or or true or whatever.
You know, this logic is mostly used.
Let's take, let's say YouTube, for example.
You see YouTube always check that.
Let's say that if you have some number of subscribers, then they can give you or they can put you on
their monetization program.
So this way we can also do something here.
So we can say that if.
Okay.
Let me say that if your age is more is less than or more than 30.
Okay, let me see.
Accounts we use count.
Yes, we use count, let's say is equal to 100.
Okay.
So let's create a function to check if your view count is less than 50.
Then we can put you on the monetization program.
Right.
So can you do something about this one to make something happen?
Well, I think this video is getting longer.
So if want to try this one, why not?
Or better still, sit down and think about a method that you can use on an object.
Right?
Because in the upcoming ones, we're going to have a lot of coding challenges.
So stick back in this video.
Let's talk about how we can attract over objects then this video.