Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
0 Hi guys. Welcome back. 1
It's Angela from The App Brewery once more. 2
So, in the last lesson we looked at the power of variables and how we can easily create them using the 3
var keyword. 4
Now in this lesson I want to cover some really important points about how you should name your variables 5
so that you're in keeping with programming best practice. 6
So currently I've still got the Snippets and the Console from the last lesson. 7
Now this is a good point to show you that if you want to clear the console because it's getting a bit 8
too messy or you're seeing too many messages, then you can simply hold down command and press K on Mac 9
and on Windows you can hold down control and press K and this will clear your console. 10
But remember this does not clear the information that's been stored inside the browser. 11
So, for example, if I write myName again, it will still know that myName has the value of Angela. 12
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
all of our cache and delete all of the data. 14
So to do that, on the Mac you can click and hold on the reload page and you will get this menu. 15
So you have Normal Reload, Hard Reload, and Empty Cache and Hard Reload. 16
So this is kind of like the supersized version of reloading. 17
And on a PC you just simply need to right click on the reload button to get that menu. 18
And now, if I click that, if I typed myName then it would not know what it is. 19
It says it's undefined. It doesn't have a clue what it is. 20
So we've managed to successfully clear all of the memory of any data. 21
So let's go ahead and delete what's inside our Snippets as well so that we start off with an empty slate. 22
And what I want to show you is that there are some rules that govern how you should name your variables. 23
Now so far we've been naming our variables myName, or yourName, and that kind of makes sense for the context 24
that we've been using it in. 25
But actually it doesn't matter what you call your name. 26
You could call it any string you like, 27
and Javascript really doesn't care. 28
But if I ask you what do you think yolsdjsj means, what would you say? If accidentally I've managed 29
to actually write a real word in Icelandic, because it's distinctly possible, 30
then maybe it'll have a meaning for the Icelandic students out there. 31
But for most people this doesn't make any sense. 32
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
but you can see that this is a really really bad idea. 34
So just because Javascript doesn't care doesn't mean that we don't care. We should care a lot, because 35
imagine working on the same project as as some guy who likes to call his variables 36
kasdkj 37
ahsdjk, 38
and you have to figure out what all of these things mean. You know, what exactly is Angela? 39
Is it, what does it mean, 40
right? 41
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
to be friends or work together, 43
right? 44
So always give meaningful names to your variables and remember that with great power comes great responsibility, 45
or even better, 46
remember that the next person who has to look after your code could very well be an axe murderer. 47
So there are some common rules that good programmers will follow, 48
first of which is, give your variables meaningful names so that anybody can figure out quite easily what 49
is the data that's likely to be stored inside it. 50
It's like if you had named all of your folders on your desktop untitled folder 1, 2, 3, 4, 51
5, 6, then you will be spending hours and hours digging through each of these folders trying to find 52
the things that you're looking for. 53
And instead if you named it pictures or movies or documents then it would be a lot easier to try and 54
figure out what they contain. 55
And it's the same story here with variable naming. 56
So aside from this, there are certain things that Javascript will not let you do when you're trying to 57
name your variables. 58
So for example I can't call my variable var because this would be insanely confusing and Javascript 59
does not actually allow you to do this. 60
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
this. But you can, however, have a variable name that contains keywords. 62
So, for example, if you called it myvar, that's totally valid, and you can see from the coloring or the 63
syntax highlighting, it's already showing you that this is valid, and this color is reserved for keywords. 64
Now the other rule is that your variable name cannot begin with a number. 65
So, for example, you can't call your variable 66
123. 67
This is also not allowed. 68
However, like keywords, your variable name can contain numbers, so you can call it my123 and that's totally 69
cool. 70
The next rule is that your variable names can't contain spaces, so it can't be my name = "Angela". 71
This makes absolutely no sense because it treats that space as if you're trying to write another different 72
bit of code. 73
The first word that comes after var and a space is going to be seen as the name of your variable. 74
So your variable is called my, 75
and so it doesn't know what to do with this extra name thing that you've squeezed in here. 76
So no spaces basically. 77
And finally the names can only contain letters, numbers, the dollar sign, and an underscore. 78
No other symbols are valid for naming a variable. 79
So, for example, you can't call your variable my-name. 80
This is not valid. 81
However, if you wish, you can call it my_name. That is a valid variable name. 82
Now finally the last thing that you'll see me do throughout the course is that I will name all of my 83
variables using camel casing and this means that I will start out the name with a lowercase word and 84
then every subsequent word will be capitalized. 85
And this is called camel casing, just as the camel humps are higher than its head, first word is not capitalized, 86
and every subsequent one is. And the reason why this is really useful is because you avoid situations like 87
TherapistFinder.com, which most people will read as TheRapistFinder.com. 88
So make sure that when you're creating your own variables that you're following the same good practice 89
that we've listed in this lesson. And in the next lesson there's a quick quiz just to test whether if 90
you've remembered and embraced some of these rules regarding variable naming. So I'll see you on the 91
next lesson.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.