WEBVTT 00:00:07.320 --> 00:00:18.120 In this video we're going to learn how to create objects and objects is a list of properties with their 00:00:18.120 --> 00:00:20.730 corresponding values. 00:00:20.730 --> 00:00:25.070 An example of objects could be a car. 00:00:25.740 --> 00:00:34.520 And the properties could be the make of the car the model the year the engine size etc.. 00:00:34.620 --> 00:00:44.130 And another example would be a person and the properties would be their first name their last name their 00:00:44.130 --> 00:00:50.460 nationality their address and the values are going to be the corresponding values of those properties 00:00:50.480 --> 00:00:51.200 . 00:00:51.900 --> 00:00:52.620 OK so 00:00:56.460 --> 00:00:59.240 let's create our first example. 00:00:59.610 --> 00:01:04.310 So we're going to create a new file We're going to call it objects 00:01:11.310 --> 00:01:19.870 and imposed the source code from alerts message a shemale file. 00:01:22.740 --> 00:01:23.550 OK. 00:01:24.130 --> 00:01:29.100 And let's just change the title to objects 00:01:31.540 --> 00:01:34.140 . 00:01:36.830 --> 00:01:37.820 OK. 00:01:38.220 --> 00:01:41.050 So the syntax is pretty easy. 00:01:41.610 --> 00:01:49.740 Basically an object is still a variable so we gonna use the javascript keyword for fall by space and 00:01:49.740 --> 00:01:51.860 then we need a name for our objects. 00:01:52.080 --> 00:01:55.190 So you know for example we going to go for my phone. 00:01:55.600 --> 00:01:56.500 Okay. 00:01:57.210 --> 00:01:58.800 And then 00:02:02.610 --> 00:02:10.070 the objects Voll properties are going to be all between two curly brackets. 00:02:10.470 --> 00:02:11.280 OK. 00:02:11.790 --> 00:02:16.640 And the way to define a property with its value is like this. 00:02:16.650 --> 00:02:23.640 So let's start with the first property the make of the phone and then call on and after that 00:02:28.800 --> 00:02:30.810 we define the value. 00:02:31.260 --> 00:02:42.280 So for instance Uppal for the make and then we separates all the properties using a comma. 00:02:42.390 --> 00:02:48.180 So the next one said the model 2 for example iPhone 4 00:02:51.710 --> 00:02:54.560 and it said the warranty. 00:02:55.380 --> 00:02:57.370 OK let's give you a number here. 00:02:57.420 --> 00:03:00.650 So it's going to be the one in months. 00:03:00.860 --> 00:03:01.680 Listen the color 00:03:06.030 --> 00:03:09.160 to white for example. 00:03:10.210 --> 00:03:11.020 OK. 00:03:11.420 --> 00:03:15.460 And we need to end our statement with a semicolon. 00:03:15.840 --> 00:03:23.670 So if we display our objects in the console Let's see what we get 00:03:29.320 --> 00:03:31.860 and save and then 00:03:35.160 --> 00:03:42.360 click on F F 12 against the console and then refresh the page and then we can see how the objects is 00:03:42.570 --> 00:03:43.710 displayed in the console. 00:03:43.710 --> 00:03:48.870 It doesn't say the name of the objects is just space objects and you can see all the properties with 00:03:48.870 --> 00:03:50.960 the corresponding values. 00:03:51.330 --> 00:03:58.860 OK so let's say we want now to delete one of the properties from the objects so we just need to use 00:03:58.860 --> 00:04:01.000 the deletes javascript keyword. 00:04:01.290 --> 00:04:12.570 OK followed by the name of our objects and it's going to say Dot the prophecy that we would like to 00:04:12.570 --> 00:04:13.270 delete. 00:04:13.500 --> 00:04:15.300 OK so let's say one of the leads. 00:04:15.300 --> 00:04:16.760 The currency. 00:04:17.270 --> 00:04:27.240 OK so if we display the objects again in the console. 00:04:27.500 --> 00:04:31.980 See what we get. 00:04:31.980 --> 00:04:38.110 So now we can see that's the currency property has been deleted. 00:04:39.180 --> 00:04:40.140 OK. 00:04:40.470 --> 00:04:52.950 So when we deleted the currency property we referred to this property using the object's name dot the 00:04:52.950 --> 00:04:54.280 name of the property. 00:04:54.570 --> 00:05:01.440 And that's how we can access any of the properties values inside the objects. 00:05:01.440 --> 00:05:13.630 So for instance if we want to access the model of the objects it is going to say my phone don't model 00:05:13.640 --> 00:05:14.830 . 00:05:15.300 --> 00:05:18.160 And this is going to be displayed in the console. 00:05:18.680 --> 00:05:20.490 OK. 00:05:20.870 --> 00:05:23.670 All right. 00:05:23.700 --> 00:05:24.480 Now let's 00:05:27.810 --> 00:05:30.010 create another object. 00:05:30.120 --> 00:05:37.590 And this time we we are going to set these new objects to be equal to our first object. 00:05:37.830 --> 00:05:41.910 So let's call it my other phone. 00:05:43.050 --> 00:05:47.520 OK let's say to be equal to my phone. 00:05:48.690 --> 00:05:50.250 So what does it what does it mean. 00:05:50.250 --> 00:05:52.580 So what are we expecting from this. 00:05:52.590 --> 00:05:56.620 So is my other phone going to be just a copy of my phone. 00:05:57.330 --> 00:05:59.740 Well actually not exactly. 00:06:00.030 --> 00:06:03.030 My other phone is going to be identical to my phone. 00:06:03.030 --> 00:06:11.020 So if we change something in my other phone it's the same thing will happen to my phone. 00:06:11.040 --> 00:06:12.690 So what do we mean by that. 00:06:12.690 --> 00:06:16.260 So first of all let's display my other phone in the console and see 00:06:19.140 --> 00:06:20.020 what we get there 00:06:29.160 --> 00:06:33.770 so we can see that both my phone and my other phone are identical. 00:06:33.840 --> 00:06:44.580 But the interesting thing is let's change something in my other phone so lets access one of the properties 00:06:46.590 --> 00:06:53.770 is accessed the model for instance and let's use it to iPhone 00:06:56.830 --> 00:07:00.410 iPhone 5. 00:07:02.340 --> 00:07:03.750 OK. 00:07:03.870 --> 00:07:11.880 So again this is how we access a property value we just need the name of the objects bought the property 00:07:12.390 --> 00:07:16.330 name and then we can sense that to any other value we want. 00:07:16.330 --> 00:07:28.710 OK so now we can check my other phone in the console in the console and see if it changed 00:07:28.860 --> 00:07:38.000 . 00:07:38.120 --> 00:07:40.880 Let's see. 00:07:40.950 --> 00:07:44.220 So the role has changed to iPhone 5. 00:07:44.560 --> 00:07:49.500 And now let's check my phone and see if the same thing happened to my phone 00:07:49.920 --> 00:07:55.410 . 00:08:00.900 --> 00:08:03.820 Honestly the same thing happened to my phone. 00:08:03.930 --> 00:08:09.990 So basically anything we change in my other phone is going to change as well in my phone. 00:08:09.990 --> 00:08:20.550 So when we said two objects to be equal to each other if any property changes in one of these is going 00:08:20.550 --> 00:08:22.150 to change in the other. 00:08:22.380 --> 00:08:22.770 So what. 00:08:22.840 --> 00:08:23.230 So. 00:08:23.230 --> 00:08:29.520 So the easiest way to see the series is by looking at an object as a reference. 00:08:29.520 --> 00:08:30.050 OK. 00:08:30.390 --> 00:08:32.150 So it's easy reference. 00:08:32.280 --> 00:08:39.450 And basically inside that reference we're going to have all the properties. 00:08:39.450 --> 00:08:50.070 So if we change if we change any property through any reference it is going to change for all objects 00:08:50.220 --> 00:08:51.620 set to that reference. 00:08:51.900 --> 00:08:56.450 OK so in our case my phone and my other phone have the same reference. 00:08:56.820 --> 00:08:57.290 OK. 00:08:57.390 --> 00:09:02.790 So anything that happens in that reference is going to affect both both of them. 00:09:03.000 --> 00:09:04.140 All right. 00:09:04.410 --> 00:09:10.500 So in the next video we are going to see another way of creating objects using the javascript's keyword 00:09:10.890 --> 00:09:11.250 new