Afrikaans
Akan
Albanian
Amharic
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
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
So with the import and export keywords
and the related concepts, we already explored a bunch
of crucial JavaScript concepts and features
which we'll use heavily throughout this course.
But of course, for this refresher
I now also want to take a step back
and also explore some other foundational JavaScript features
and concepts like working
with variables, values, functions, objects, and much more.
And it definitely makes sense to start
with variables, values, and operators, for that.
In this app js file, I'll comment
out all this code we wrote before
because we don't need it here, and instead
I now do want to revisit some foundational concepts related
to variables and values and operators.
Because in the end, when you're building an app
with JavaScript or with React, which uses JavaScript
of course it's in the end all about data and therefore
in the end values you are working with in your code.
If you take a look
at applications like Twitter or Google Maps, those apps
like all apps of course in the end are about data.
The tweets you write and read are data.
Your location is data.
The location you want to go to is data.
All these things are data that must be handled
in your code and in your Java script code.
You can therefore handle a broad variety of values.
Most importantly, strings, numbers, booleans.
This the special null and undefined values
which simply mean that a certain data container
a certain variable, doesn't contain any values yet.
And also the special object value to which I'll get back
later, now, a value in JavaScript can be created
in the place where you need it.
For example, if I want to output hello world here
I can simply create the string.
Hello world with double or single quotes, doesn't matter
but quotes are of course needed.
And if I then save this and reload my app
I would see hello world in the console.
So I can create values when I need them.
For example, here, when I need a value
as an input for this console
log command that's built into the browser in the end.
But it's also quite common that values should be stored.
And for that, you're using variables.
Variables are simply data containers where you store a value
in a variable which carries any name of your choice.
So you assign a name to a variable
and you can then use this variable name as an identifier
in your code to refer to that value that's stored
in this variable whenever you need to use that value.
And you typically use variables
because they allow you to reuse a value
and because they can help with code readability
because often it makes sense to not define the value
in the place where it's needed, but maybe instead ahead
of time so that your overall code stays a bit cleaner
and more readable.
Now, in JavaScript variables can be created
with the let keyword here.
I could create a variable named user message
though the name is up to you
it just should follow certain rules.
For example, it should be written using this camel
case notation where you start with a lowercase character.
And if your variable name then consists of multiple words
every word inside of the word
like message here starts with a capital case character
and it must not contain any dashes or white space.
So this variable name would be invalid just
as this name would be, underscores would be allowed
but are not common in JavaScript.
Instead, as mentioned
the convention is to use this notation.
Variable names also may contain numbers
but not at the beginning.
In addition
they also may not contain any special characters
like an exclamation mark or a question mark.
The only exception is the dollar sign and the underscore
which I already mentioned.
But other than that, the name is up to you.
And then I could store this hello world text
in user message.
If I then want to use this value, for example here
for logging it to the console, I would simply use the name
of the variable and thereby refer to this value.
And that's how I use a variable.
And if I now want to lock this multiple times, for example
I gain this reusability advantage by using a variable
because instead of having to copy and paste that value
I just define it once and then use that variable as often
as I want to use that value that has the advantage that
if that value ever needs to change, I only need to change it
in one place instead of multiple places.
And all the places in my code where I use that variable
will automatically use that changed value, with that.
If I reload this, I of course see hello world being output
in the console twice.
So that's how we create variables.
Now, related to variables, we also have constants
which are created with the const keyword.
If I save this and reload, I again see HelloWorld being
output twice here.
So constants work like variables, they are data containers.
But the key differences that constants must not be
reassigned, if I try to assign a new value,
a new string, for example, like this
I'm getting an error
that it's read only because it's a constant.
If I were using let here instead of const
everything would work instead.
Now I would again see my log here in the console.
So that's the key difference
with let, I can use this single equal sign operator to
assign a new value, with const, I can't.
Now, there are different philosophies out there.
In the JavaScript world
certain developers like to use const as often as possible
and I am one of those developers.
Other developers want to use let all the time
because it has less characters
and therefore requires less code to type.
But I prefer to be clear about my intentions
and if I have a value that never should be reassigned.
I personally prefer to use const.
You can use whatever you want
but you should know about the difference.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.