Hello, in this JavaScript video, I am going to show you variables in relation to classes. So let's have a look at how we can create variables in a class in JavaScript. So to create any, you go to constructor, just put this.in the name of the variable. So I'm going to create one for x and y. So this will equal x. And we'll create one for y.
So this dot y equals one, okay, and to access these values, we simply console log, console log, and also no auditing or supreme brackets, and then we'll put the value of it. So value is called OBJ. Or whatever the your call object is called dot x or the variable name plus Karma. Again, this is the formatting part of it, where you the hell, totally up to you, but the accent is caught, you know OBJ dot exe and called da da. Say that right? We Yeah, forget to put a comma at the end.
And no come on closing bracket on me. There we go Okay, we got those on you duplicate this one I'm going to duplicate this one here. So it's gonna be separate core object and I want to say is position is 90, and zero and what we'll do is coordinate so you can see that each one has its own different properties and variables to those 5678 90 and zero. And as you can see, we've got two different objects And we have variables. So that's how you create a variable inside of it in the constructor, just do like this dot, you know, x, for example, don't have to assign a value straight away. It's always good to have default value.
They could even be passed in or, you know, maybe by default x and y, zero, and zero, who let's say it's the name of the call. You might have a default name or owner or you know, something along those lines. I think of variables in class. If you have any questions, feel free to shoot me a message and I'm forcing you next video.