Hello, in this JavaScript video, I am going to show you classes I'm not going to show you everything or the different features of clapping yet. There are separate video covering all of that. I'm going to show you a simple example. Okay, so what is a class? You know, to begin with, that's probably the first thing that has gone through your head. So we've heard of people object oriented programming classes is, you know, that's what it is.
If you have a class, which allows you to sort of abstract encapsulate properties, such as variable and methods for common functionality, maybe have a call, for example, where you we will actually use that and that will have properties and maybe like position speed, and then you'll have methods to maybe move the car to destroy the car, let's say it's a game. And then you would create an object of said class. And if we go back to the videos where we actually covered objects, all objects were classes in some form. already built in, we're going to create our own now. And you can add whatever functionality you want. And we can create as many as we want.
So we have this amazing car class that has 546 lines of code. You don't have to use to create those 146 lines every time. You want to create a new car, use kitchen, you object inherits all of that, you know all of the properties of that class, and you just use it. So it's really, really cool. So let's just dive into it. And the first thing we'll do is the keyword class.
Then you want to name your classrooms, they call it braces, and in here, we need something called a row. So this is a method and this method is actually run when you first create the object. So console dot log and other say see The Chinese for 10. Yeah, so so this is the struct. And let's expand this a bit and create an object for this. And you just literally do a VAR name, your object for this is a product called OBJ equals new.
The name of the actual class, you use it. And now if I run it says this is a constructor, but you're calling this out. This is a constructor does not get printed out in the console. And that's because even though we have to specifically call this method when we create an object of it, it creates I mean, he calls the constructor and technically these brackets here, that's what is calling the constructor. So in a way we have caught it but we haven't like done something like doc construct or anything. This is the first one that is called so nice set.
For the class that you need to do, do it in the constructor. So that this is a very basic example, let me add in over naturally, I'm going to keep that for a separate video function. One thing I want to show you the constructor, just like normal functions can take variables. So if I say x comma y, so these are the variable names, and maybe I print them out, so I just console dot log x position is x, y. But now if we run it, what happens? We get undefined.
And the reason for that is you haven't actually pass any values in, we need to make sure we pass them so let's say this starting position 5678 there shouldn't be a comma There are about that. And if I reload, does it get passed in. So that's pretty cool. And you can, you know, obviously, store those values in variables as well. I'm going to cover variables inside of a class in a whole nother video, so feel free to take a look at that. And as usual, thanks for watching, and I look forward to seeing you in the next tutorial.