1 00:00:00,550 --> 00:00:03,720 In this video, you'll be learning about changing properties and 2 00:00:03,720 --> 00:00:05,550 adding them to object literals. 3 00:00:05,550 --> 00:00:08,170 Everything you're learning in this stage of the course is to get you 4 00:00:08,170 --> 00:00:12,270 really comfortable with the basics of objects and object syntax. 5 00:00:12,270 --> 00:00:14,588 Object literals are just one way to create objects, but 6 00:00:14,588 --> 00:00:16,325 they're a great way to learn the basics. 7 00:00:16,325 --> 00:00:19,758 So that you're ready to hit the ground running with more advanced object 8 00:00:19,758 --> 00:00:21,569 discussions later on in this course. 9 00:00:22,728 --> 00:00:26,640 Remember, object oriented programming is about designing programs that use 10 00:00:26,640 --> 00:00:29,340 objects for the primary logic of the program. 11 00:00:29,340 --> 00:00:32,210 To do that, you need to have a good grasp of the syntax for 12 00:00:32,210 --> 00:00:34,260 how we create and interact with objects. 13 00:00:35,340 --> 00:00:39,040 Now that we know how to access properties using dot and bracket notation, 14 00:00:39,040 --> 00:00:43,020 we can build on that knowledge to change or manipulate properties. 15 00:00:43,020 --> 00:00:47,110 We can also use this knowledge to add new properties to object literals. 16 00:00:47,110 --> 00:00:50,140 We're going to keep working with the ernie object literal from the previous two 17 00:00:50,140 --> 00:00:51,140 videos. 18 00:00:51,140 --> 00:00:54,050 Ernie is a year old right now, but time will go on, and 19 00:00:54,050 --> 00:00:55,746 he will eventually get older. 20 00:00:55,746 --> 00:01:00,089 When he turns two, we'll need to update his age property. 21 00:01:00,089 --> 00:01:04,330 Remember when I referred to properties as object specific variables? 22 00:01:04,330 --> 00:01:09,590 Well, just like we would update a regular variable, we can update a property. 23 00:01:09,590 --> 00:01:10,910 You can use either dot or 24 00:01:10,910 --> 00:01:16,850 bracket notation to access the property, then simply set it equal to the new value. 25 00:01:16,850 --> 00:01:23,990 For dot notation, that means ernie.age = 2. 26 00:01:23,990 --> 00:01:28,801 To change the age property using bracket notation, 27 00:01:28,801 --> 00:01:32,199 you'll do ernie['age'] = 2. 28 00:01:32,199 --> 00:01:36,346 Interestingly, for both dot and bracket notation, 29 00:01:36,346 --> 00:01:42,550 you would use the same syntax to add a property to an object literal. 30 00:01:42,550 --> 00:01:46,057 For example, Ernie doesn't currently have a color property. 31 00:01:46,057 --> 00:01:49,625 If we wanted to give him one, 32 00:01:49,625 --> 00:01:55,587 we would simply do ernie.color = 'black'. 33 00:01:55,587 --> 00:01:59,527 Let's check what's going on inside our object literal by logging the value of 34 00:01:59,527 --> 00:02:01,929 ernie to the console and then running our file. 35 00:02:06,280 --> 00:02:09,500 I'm gonna save it and then go back down here and run the file. 36 00:02:13,870 --> 00:02:16,761 Perfect, as we can see down in the console, 37 00:02:16,761 --> 00:02:20,370 Ernie now has a new property called color, great job. 38 00:02:20,370 --> 00:02:21,666 In this stage of the course, 39 00:02:21,666 --> 00:02:24,259 you learned all about working with the object literals. 40 00:02:24,259 --> 00:02:26,343 You mastered dot and bracket notation, and 41 00:02:26,343 --> 00:02:30,040 you learned how to add properties to object literals as well. 42 00:02:30,040 --> 00:02:33,213 Check out the teacher's notes to find some additional opportunities for 43 00:02:33,213 --> 00:02:34,500 practicing these concepts. 44 00:02:34,500 --> 00:02:38,451 And then join me in the next stage to continue your object oriented journey.