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
French
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
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
Let's start this section by a discussion
of variables, which are one of the most fundamental concepts in JavaScript
and any other programming languages. In programming,
use a variable to store data temporarily in the computers
memory. So we store our data somewhere, and give that memory
location a name. And with this name, we can read the data at the
given location in the future. Here's a metaphor. Think
of the boxes you use to organize your stuff. You put your stuff in various
boxes, and put a label on each box. With this, you can
easily find your stuff. A variable is like a box.
What we put inside the box, is the value that we assign to
a variable, that's the data, and the label that we put on the box
is the name of our variable. Now let's see this in code.
So here in index.js, I'm going to declare a variable. Now,
previously in the old days, before ES6, we used the
var keyword to declare a variable. But there are issues with
var as you will find out later in the course. So, going forward
from ES6, the best practice is to use the
let keyword to declare a variable. Now, we need to give this variable
a name, or an identifier, and this is like the label we put
on a box. So I'm going to call this name, and finally we need to
terminate this declaration with a semi colon. Now let's log this
on the console and see what we get. So console.log
name, once again we need to terminate this statement
with a semi colon. Save the changes, and here in the console
we see undefined. So by default variables
that we defined in JavaScript, their value is undefined. Now we can optionally
initialize this variable. So I'm going to set this
to be a string, which is a sequence of characters,
like Mosh. Note that I'm using single quotes,
we can also use double quotes, different developers have different
purposes, but it's more common to use single quotes for declaring strings,
in JavaScript. Now when you save the changes,
instead of undefined, we see Mosh on the console. So,
here in this example we have declared a variable called name, and we have set that to
this value, to this string. Now, we have a few rules
for naming these variables. Here are the rules,
first is that they cannot be a reserved
keyword. So in JavaScript we have reserved keywords,
let is one of them. We also have if, l's
var and so on. Now you don't have to memorize this list, if you try
to use one of these names, you're going to get an error. For example, if I change this
to if note this red underline.
This is indicating that this is not a valid identifier, okay?
So, we wrote it back, now, the second rule
is that they should be meaningful. We want to have meaningful
names, like meaningful labels. I've seen developers using
names like a or b or a1 or
I don't know, x. These variable names don't give us any clue what is
the purpose of these variables. What kind of data are we
storing in that memory location? So always use meaningful and descriptive
names. Okay? Now, back to name
the third rule is that they
cannot start on a number. So we cannot have a variable like 1
name. But again, going back to the same rule, why would you want to call
a variable 1name? It's meaningless, right?
So, always use meaningful names. The fourth rule
is that they cannot contain a space or hyphen.
So if you have multiple
words we need to put them together. Here is an example, let's imagine we want to declare a
variable called first name. So firstName
and note that here I'm using camel notation, so the first
letter of the first word should be lowercase, and
the first letter of every word after should be upper case. This
is what we call camel notation, which is the convention we use in
JavaScript to name our variables. Another thing you need to know about
these variable names, is that they are
case-sensitive, so if I declare another variable,
call it first name, but make the f upper case,
these two variables are different. But as I told you
before, if you stick to camel (?) notation, you will end up with a variable
name like this. And finally the last thing you need to know about these
variables, is that if you want to declare multiple variables, there are
two ways to do this. You can declare them on one line
and separate them using a comma, so first name, then last
name. Now in this case, I have not initialized either of these
variables, they're both undefined, I can optionally initialize
1 or both of them, so I can set this to Mosh, and I can
leave lastName undefined or set it to my last name, Hamedani,
but the modern best practice is to declare each variable
on a single line. So we terminate
this first declaration with a semi-colon, and I declare the second variable on a new line.
That's the modern best practice.
Next we're going to look at constants.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.