1 00:00:02,110 --> 00:00:04,290 Now let me get rid of that existing code, 2 00:00:04,470 --> 00:00:08,560 you find a snapshot of the code we wrote thus far attached to the last lecture and 3 00:00:09,630 --> 00:00:11,220 let me write some new code. 4 00:00:11,250 --> 00:00:18,780 An important thing you work with or important data structure you work with in javascript are objects. 5 00:00:18,780 --> 00:00:24,060 You could have something like the person object and you create an object typically with curly braces 6 00:00:24,480 --> 00:00:27,270 and then in there, you have key value pairs. 7 00:00:27,540 --> 00:00:33,110 You define the key by simply typing, well whichever key you want to use, let's say name 8 00:00:33,120 --> 00:00:37,500 then you have a colon, you must have the colon and after the colon, 9 00:00:37,500 --> 00:00:38,690 you have your value, 10 00:00:38,730 --> 00:00:43,840 in my case a string Max and then with a comma, you can add another key value pair, 11 00:00:43,890 --> 00:00:46,050 age 29. 12 00:00:46,050 --> 00:00:55,280 Now this is an object and I can log person here, if I now execute play.js, we see that object being 13 00:00:55,280 --> 00:00:56,490 printed here. 14 00:00:56,800 --> 00:01:00,020 Now objects allow us to group data together, 15 00:01:00,050 --> 00:01:06,900 you can also not just have variables in there so to say but you can also have functions in there, 16 00:01:07,010 --> 00:01:14,700 for example a greet function and there you can simply have an anonymous arrow function or an arrow function 17 00:01:14,720 --> 00:01:20,390 general as a value after the colon and then in there, you could have console log 18 00:01:20,650 --> 00:01:24,200 Hi I am 19 00:01:24,660 --> 00:01:30,270 and then the name and this would now be accessed with the this keyword, instead of an object you have 20 00:01:30,270 --> 00:01:32,020 to use this to 21 00:01:32,100 --> 00:01:37,240 typically and there is something special about this which I showed in that video I linked before 22 00:01:37,240 --> 00:01:38,610 in an earlier lecture 23 00:01:38,610 --> 00:01:42,340 but typically this refers to the surrounding object 24 00:01:42,510 --> 00:01:45,050 and now we can use the dot notation, 25 00:01:45,230 --> 00:01:48,870 so dot to access properties or methods, 26 00:01:48,870 --> 00:01:51,630 so variables or functions inside of that object, 27 00:01:51,630 --> 00:01:54,330 so we could now use this name. 28 00:01:54,520 --> 00:02:02,280 And now I can use that person and call greet with the dot notation and executing it as a function, 29 00:02:02,320 --> 00:02:08,860 so the dot notation is important on this which refers to the object or on you, referring to that object 30 00:02:08,860 --> 00:02:14,680 which is stored in this constant here. And now if I execute this again, I'm saying hey I'm undefined, 31 00:02:14,710 --> 00:02:15,770 now why is that? 32 00:02:15,940 --> 00:02:20,880 Well the reason for that indeed is what I talked here about arrow functions. 33 00:02:21,070 --> 00:02:30,100 This now here refers to the global scope, to the global node runtime scope and not to this object, to 34 00:02:30,100 --> 00:02:32,020 have it refer to that, 35 00:02:32,020 --> 00:02:40,830 we either have to use the old school function, like this. Now if I repeat that, I'm saying Hey I'm Max or 36 00:02:41,250 --> 00:02:46,550 we use a slightly different approach or syntax here in an object 37 00:02:46,800 --> 00:02:51,000 and that is you don't use an arrow function but you use greet like that. 38 00:02:51,150 --> 00:02:58,680 So you omit the colon, add the parentheses after the key name and then without a function keyword or 39 00:02:58,680 --> 00:03:01,970 anything like that, you add your function body 40 00:03:02,070 --> 00:03:04,950 and now this is a method of this object 41 00:03:05,040 --> 00:03:05,770 and you see 42 00:03:05,820 --> 00:03:07,480 Hi I'm Max too now. 43 00:03:07,680 --> 00:03:13,320 So this is something important and this is the syntax you'll see me use throughout this course, without the colon 44 00:03:13,470 --> 00:03:17,340 parentheses right after the key and then the function body.