All language subtitles for 8. Naming and Naming Conventions for Javascript Variables

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 0 1 00:00:00,270 --> 00:00:01,980 Hi guys. Welcome back. 1 2 00:00:02,040 --> 00:00:04,360 It's Angela from The App Brewery once more. 2 3 00:00:04,380 --> 00: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 4 00:00:10,490 --> 00:00:11,780 var keyword. 4 5 00:00:11,790 --> 00:00:17,730 Now in this lesson I want to cover some really important points about how you should name your variables 5 6 00:00:17,970 --> 00:00:21,210 so that you're in keeping with programming best practice. 6 7 00:00:21,210 --> 00:00:26,340 So currently I've still got the Snippets and the Console from the last lesson. 7 8 00:00:26,340 --> 00: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 9 00:00:31,140 --> 00: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 10 00:00:38,400 --> 00:00:43,440 and on Windows you can hold down control and press K and this will clear your console. 10 11 00:00:43,530 --> 00:00:48,590 But remember this does not clear the information that's been stored inside the browser. 11 12 00:00:48,600 --> 00:00:55,840 So, for example, if I write myName again, it will still know that myName has the value of Angela. 12 13 00:00:55,920 --> 00: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 14 00:01:01,710 --> 00:01:04,290 all of our cache and delete all of the data. 14 15 00:01:04,440 --> 00: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 16 00:01:12,330 --> 00:01:16,800 So you have Normal Reload, Hard Reload, and Empty Cache and Hard Reload. 16 17 00:01:16,800 --> 00:01:21,670 So this is kind of like the supersized version of reloading. 17 18 00:01:21,810 --> 00:01:27,500 And on a PC you just simply need to right click on the reload button to get that menu. 18 19 00:01:27,690 --> 00:01:33,410 And now, if I click that, if I typed myName then it would not know what it is. 19 20 00:01:33,420 --> 00:01:36,150 It says it's undefined. It doesn't have a clue what it is. 20 21 00:01:36,150 --> 00:01:40,380 So we've managed to successfully clear all of the memory of any data. 21 22 00:01:40,380 --> 00: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 23 00:01:46,980 --> 00: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 24 00:01:53,760 --> 00: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 25 00:02:01,320 --> 00:02:02,690 that we've been using it in. 25 26 00:02:02,730 --> 00:02:06,510 But actually it doesn't matter what you call your name. 26 27 00:02:06,630 --> 00:02:09,480 You could call it any string you like, 27 28 00:02:09,480 --> 00:02:11,960 and Javascript really doesn't care. 28 29 00:02:12,120 --> 00:02:20,160 But if I ask you what do you think yolsdjsj means, what would you say? If accidentally I've managed 29 30 00:02:20,160 --> 00:02:25,670 to actually write a real word in Icelandic, because it's distinctly possible, 30 31 00:02:25,800 --> 00:02:30,110 then maybe it'll have a meaning for the Icelandic students out there. 31 32 00:02:30,210 --> 00:02:33,610 But for most people this doesn't make any sense. 32 33 00:02:33,690 --> 00: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 34 00:02:41,940 --> 00:02:44,740 but you can see that this is a really really bad idea. 34 35 00:02:44,820 --> 00: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 36 00:02:51,630 --> 00:02:56,810 imagine working on the same project as as some guy who likes to call his variables 36 37 00:02:56,820 --> 00:02:57,480 kasdkj 37 38 00:02:57,490 --> 00:02:58,590 ahsdjk, 38 39 00:02:58,800 --> 00:03:04,880 and you have to figure out what all of these things mean. You know, what exactly is Angela? 39 40 00:03:04,950 --> 00:03:07,470 Is it, what does it mean, 40 41 00:03:07,470 --> 00:03:08,050 right? 41 42 00:03:08,220 --> 00: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 43 00:03:14,550 --> 00:03:16,660 to be friends or work together, 43 44 00:03:16,680 --> 00:03:17,490 right? 44 45 00:03:17,490 --> 00:03:25,470 So always give meaningful names to your variables and remember that with great power comes great responsibility, 45 46 00:03:25,650 --> 00:03:26,700 or even better, 46 47 00:03:26,700 --> 00:03:32,570 remember that the next person who has to look after your code could very well be an axe murderer. 47 48 00:03:32,640 --> 00:03:36,720 So there are some common rules that good programmers will follow, 48 49 00:03:37,020 --> 00:03:43,890 first of which is, give your variables meaningful names so that anybody can figure out quite easily what 49 50 00:03:43,890 --> 00:03:47,020 is the data that's likely to be stored inside it. 50 51 00:03:47,160 --> 00:03:52,890 It's like if you had named all of your folders on your desktop untitled folder 1, 2, 3, 4, 51 52 00:03:52,890 --> 00:03:58,560 5, 6, then you will be spending hours and hours digging through each of these folders trying to find 52 53 00:03:58,560 --> 00:04:00,270 the things that you're looking for. 53 54 00:04:00,270 --> 00: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 55 00:04:06,720 --> 00:04:08,580 figure out what they contain. 55 56 00:04:08,580 --> 00:04:11,110 And it's the same story here with variable naming. 56 57 00:04:11,130 --> 00:04:16,440 So aside from this, there are certain things that Javascript will not let you do when you're trying to 57 58 00:04:16,440 --> 00:04:17,580 name your variables. 58 59 00:04:17,580 --> 00:04:24,960 So for example I can't call my variable var because this would be insanely confusing and Javascript 59 60 00:04:24,960 --> 00:04:27,390 does not actually allow you to do this. 60 61 00:04:27,420 --> 00: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 62 00:04:32,880 --> 00:04:39,290 this. But you can, however, have a variable name that contains keywords. 62 63 00:04:39,540 --> 00: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 64 00:04:46,680 --> 00:04:53,240 syntax highlighting, it's already showing you that this is valid, and this color is reserved for keywords. 64 65 00:04:53,250 --> 00:04:59,070 Now the other rule is that your variable name cannot begin with a number. 65 66 00:04:59,340 --> 00:05:02,160 So, for example, you can't call your variable 66 67 00:05:02,160 --> 00:05:03,290 123. 67 68 00:05:03,300 --> 00:05:05,770 This is also not allowed. 68 69 00:05:05,780 --> 00:05:13,920 However, like keywords, your variable name can contain numbers, so you can call it my123 and that's totally 69 70 00:05:13,920 --> 00:05:14,490 cool. 70 71 00:05:14,490 --> 00:05:23,140 The next rule is that your variable names can't contain spaces, so it can't be my name = "Angela". 71 72 00:05:23,490 --> 00:05:29,880 This makes absolutely no sense because it treats that space as if you're trying to write another different 72 73 00:05:29,880 --> 00:05:30,780 bit of code. 73 74 00:05:30,810 --> 00: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 75 00:05:38,410 --> 00:05:41,190 So your variable is called my, 75 76 00:05:41,190 --> 00:05:46,470 and so it doesn't know what to do with this extra name thing that you've squeezed in here. 76 77 00:05:46,620 --> 00:05:48,750 So no spaces basically. 77 78 00:05:48,840 --> 00:05:55,990 And finally the names can only contain letters, numbers, the dollar sign, and an underscore. 78 79 00:05:56,070 --> 00:06:00,580 No other symbols are valid for naming a variable. 79 80 00:06:00,780 --> 00:06:05,480 So, for example, you can't call your variable my-name. 80 81 00:06:05,490 --> 00:06:06,720 This is not valid. 81 82 00:06:06,780 --> 00:06:12,750 However, if you wish, you can call it my_name. That is a valid variable name. 82 83 00:06:12,750 --> 00: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 84 00:06:18,960 --> 00:06:26,640 variables using camel casing and this means that I will start out the name with a lowercase word and 84 85 00:06:26,640 --> 00:06:30,050 then every subsequent word will be capitalized. 85 86 00:06:30,090 --> 00: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 87 00:06:37,080 --> 00:06:43,450 and every subsequent one is. And the reason why this is really useful is because you avoid situations like 87 88 00:06:43,470 --> 00:06:49,980 TherapistFinder.com, which most people will read as TheRapistFinder.com. 88 89 00:06:49,980 --> 00:06:55,380 So make sure that when you're creating your own variables that you're following the same good practice 89 90 00:06:55,380 --> 00: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 91 00:07:01,350 --> 00:07:08,670 you've remembered and embraced some of these rules regarding variable naming. So I'll see you on the 91 92 00:07:08,670 --> 00:07:09,460 next lesson. 10235

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.