WEBVTT 0 00:00.270 --> 00:01.980 Hi guys. Welcome back. 1 00:02.040 --> 00:04.360 It's Angela from The App Brewery once more. 2 00:04.380 --> 00:10.470 So, in the last lesson we looked at the power of variables and how we can easily create them using the 3 00:10.490 --> 00:11.780 var keyword. 4 00:11.790 --> 00:17.730 Now in this lesson I want to cover some really important points about how you should name your variables 5 00:17.970 --> 00:21.210 so that you're in keeping with programming best practice. 6 00:21.210 --> 00:26.340 So currently I've still got the Snippets and the Console from the last lesson. 7 00:26.340 --> 00:31.140 Now this is a good point to show you that if you want to clear the console because it's getting a bit 8 00:31.140 --> 00:38.160 too messy or you're seeing too many messages, then you can simply hold down command and press K on Mac 9 00:38.400 --> 00:43.440 and on Windows you can hold down control and press K and this will clear your console. 10 00:43.530 --> 00:48.590 But remember this does not clear the information that's been stored inside the browser. 11 00:48.600 --> 00:55.840 So, for example, if I write myName again, it will still know that myName has the value of Angela. 12 00:55.920 --> 01:01.710 So in order to clear all of the data we're going to have to do a hard clean. We're going to have to empty 13 01:01.710 --> 01:04.290 all of our cache and delete all of the data. 14 01:04.440 --> 01:12.180 So to do that, on the Mac you can click and hold on the reload page and you will get this menu. 15 01:12.330 --> 01:16.800 So you have Normal Reload, Hard Reload, and Empty Cache and Hard Reload. 16 01:16.800 --> 01:21.670 So this is kind of like the supersized version of reloading. 17 01:21.810 --> 01:27.500 And on a PC you just simply need to right click on the reload button to get that menu. 18 01:27.690 --> 01:33.410 And now, if I click that, if I typed myName then it would not know what it is. 19 01:33.420 --> 01:36.150 It says it's undefined. It doesn't have a clue what it is. 20 01:36.150 --> 01:40.380 So we've managed to successfully clear all of the memory of any data. 21 01:40.380 --> 01:46.730 So let's go ahead and delete what's inside our Snippets as well so that we start off with an empty slate. 22 01:46.980 --> 01:53.750 And what I want to show you is that there are some rules that govern how you should name your variables. 23 01:53.760 --> 02:01.320 Now so far we've been naming our variables myName, or yourName, and that kind of makes sense for the context 24 02:01.320 --> 02:02.690 that we've been using it in. 25 02:02.730 --> 02:06.510 But actually it doesn't matter what you call your name. 26 02:06.630 --> 02:09.480 You could call it any string you like, 27 02:09.480 --> 02:11.960 and Javascript really doesn't care. 28 02:12.120 --> 02:20.160 But if I ask you what do you think yolsdjsj means, what would you say? If accidentally I've managed 29 02:20.160 --> 02:25.670 to actually write a real word in Icelandic, because it's distinctly possible, 30 02:25.800 --> 02:30.110 then maybe it'll have a meaning for the Icelandic students out there. 31 02:30.210 --> 02:33.610 But for most people this doesn't make any sense. 32 02:33.690 --> 02:41.860 And when I try to use it or print it, I mean I can if I remember it exactly the way that I typed it, 33 02:41.940 --> 02:44.740 but you can see that this is a really really bad idea. 34 02:44.820 --> 02:51.630 So just because Javascript doesn't care doesn't mean that we don't care. We should care a lot, because 35 02:51.630 --> 02:56.810 imagine working on the same project as as some guy who likes to call his variables 36 02:56.820 --> 02:57.480 kasdkj 37 02:57.490 --> 02:58.590 ahsdjk, 38 02:58.800 --> 03:04.880 and you have to figure out what all of these things mean. You know, what exactly is Angela? 39 03:04.950 --> 03:07.470 Is it, what does it mean, 40 03:07.470 --> 03:08.050 right? 41 03:08.220 --> 03:14.550 It's kind of like if you only speak English and wǒ zhǐ huì shuō zhōngwén, it would be pretty hard for us 42 03:14.550 --> 03:16.660 to be friends or work together, 43 03:16.680 --> 03:17.490 right? 44 03:17.490 --> 03:25.470 So always give meaningful names to your variables and remember that with great power comes great responsibility, 45 03:25.650 --> 03:26.700 or even better, 46 03:26.700 --> 03:32.570 remember that the next person who has to look after your code could very well be an axe murderer. 47 03:32.640 --> 03:36.720 So there are some common rules that good programmers will follow, 48 03:37.020 --> 03:43.890 first of which is, give your variables meaningful names so that anybody can figure out quite easily what 49 03:43.890 --> 03:47.020 is the data that's likely to be stored inside it. 50 03:47.160 --> 03:52.890 It's like if you had named all of your folders on your desktop untitled folder 1, 2, 3, 4, 51 03:52.890 --> 03:58.560 5, 6, then you will be spending hours and hours digging through each of these folders trying to find 52 03:58.560 --> 04:00.270 the things that you're looking for. 53 04:00.270 --> 04:06.720 And instead if you named it pictures or movies or documents then it would be a lot easier to try and 54 04:06.720 --> 04:08.580 figure out what they contain. 55 04:08.580 --> 04:11.110 And it's the same story here with variable naming. 56 04:11.130 --> 04:16.440 So aside from this, there are certain things that Javascript will not let you do when you're trying to 57 04:16.440 --> 04:17.580 name your variables. 58 04:17.580 --> 04:24.960 So for example I can't call my variable var because this would be insanely confusing and Javascript 59 04:24.960 --> 04:27.390 does not actually allow you to do this. 60 04:27.420 --> 04:32.880 You can see that we've got this little error here and it already tells us that we can't structure our code like 61 04:32.880 --> 04:39.290 this. But you can, however, have a variable name that contains keywords. 62 04:39.540 --> 04:46.680 So, for example, if you called it myvar, that's totally valid, and you can see from the coloring or the 63 04:46.680 --> 04:53.240 syntax highlighting, it's already showing you that this is valid, and this color is reserved for keywords. 64 04:53.250 --> 04:59.070 Now the other rule is that your variable name cannot begin with a number. 65 04:59.340 --> 05:02.160 So, for example, you can't call your variable 66 05:02.160 --> 05:03.290 123. 67 05:03.300 --> 05:05.770 This is also not allowed. 68 05:05.780 --> 05:13.920 However, like keywords, your variable name can contain numbers, so you can call it my123 and that's totally 69 05:13.920 --> 05:14.490 cool. 70 05:14.490 --> 05:23.140 The next rule is that your variable names can't contain spaces, so it can't be my name = "Angela". 71 05:23.490 --> 05:29.880 This makes absolutely no sense because it treats that space as if you're trying to write another different 72 05:29.880 --> 05:30.780 bit of code. 73 05:30.810 --> 05:38.400 The first word that comes after var and a space is going to be seen as the name of your variable. 74 05:38.410 --> 05:41.190 So your variable is called my, 75 05:41.190 --> 05:46.470 and so it doesn't know what to do with this extra name thing that you've squeezed in here. 76 05:46.620 --> 05:48.750 So no spaces basically. 77 05:48.840 --> 05:55.990 And finally the names can only contain letters, numbers, the dollar sign, and an underscore. 78 05:56.070 --> 06:00.580 No other symbols are valid for naming a variable. 79 06:00.780 --> 06:05.480 So, for example, you can't call your variable my-name. 80 06:05.490 --> 06:06.720 This is not valid. 81 06:06.780 --> 06:12.750 However, if you wish, you can call it my_name. That is a valid variable name. 82 06:12.750 --> 06:18.960 Now finally the last thing that you'll see me do throughout the course is that I will name all of my 83 06:18.960 --> 06:26.640 variables using camel casing and this means that I will start out the name with a lowercase word and 84 06:26.640 --> 06:30.050 then every subsequent word will be capitalized. 85 06:30.090 --> 06:36.980 And this is called camel casing, just as the camel humps are higher than its head, first word is not capitalized, 86 06:37.080 --> 06:43.450 and every subsequent one is. And the reason why this is really useful is because you avoid situations like 87 06:43.470 --> 06:49.980 TherapistFinder.com, which most people will read as TheRapistFinder.com. 88 06:49.980 --> 06:55.380 So make sure that when you're creating your own variables that you're following the same good practice 89 06:55.380 --> 07:01.350 that we've listed in this lesson. And in the next lesson there's a quick quiz just to test whether if 90 07:01.350 --> 07:08.670 you've remembered and embraced some of these rules regarding variable naming. So I'll see you on the 91 07:08.670 --> 07:09.460 next lesson.