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
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
Now that we're getting
more comfortable with JavaScript,
it's time to learn about a more theoretical concept.
And that's the difference
between statements and expressions.
And this is gonna be just a very high level overview,
just so that the future lecturers make more sense.
So essentially, an expression is a piece of code
that produces a value.
For example, three plus four is an expression
because this is gonna produce a value, okay?
So I don't even mean the entire line of code.
What I mean is really just this three plus four.
This is an expression, okay?
And again, because it does produce a value.
The same goes, for example for just any number.
This for example is an expression too,
even though it's just a simple value.
But it's still also an expression,
because again, this itself
will produce a value in JavaScript.
Or we can do this.
So true and false and,
not false.
So all of this here,
is an expression, right?
Because this will in the end, produce some Boolean value.
Now, on the other hand, we have statements.
And the statement is like a bigger piece of code
that is executed
and which does not produce a value on itself.
And we can compare this with normal spoken language.
And so in this example,
a declaration is like a complete sentence
and expressions are like the words
that make up the sentences.
Now, basically we write our whole programs
as a sequence of actions.
And these actions are statements.
So let's take as an example, the, if else, statement.
So let's say,
if 23 is greater than 10,
then, well just do something.
So create a string called, 23 is bigger.
The code itself doesn't really matter here.
So this, if else statement is in fact a statement.
And so that's the reason why I have called it
the if else statement all the time.
And the same is true for the switch statement.
So this statement here
doesn't really produce a value, does it?
All it does is, in this case,
it simply declares is variable called STR.
But that's it.
It performs some actions,
in this case, declaring this variable,
but it doesn't produce a value.
And so in that, it's different from,
for example, having this here, okay?
Now the string itself, again is an expression.
So this is probably a bit confusing,
but that's not a problem, okay?
My goal here is not that you understand
the exact rules of what an expression is
and what a statement is,
because, in fact, it's all a bit fuzzy.
So my main goal with this lecture is really
that you know that statements and expressions exist,
and that expressions produce values,
and that statements are like full sentences
that translate our actions.
So the actions that we want the program to perform, okay?
So really that's all you need to know,
and all you need to basically memorize from this video.
We don't need to go into all the details.
So there's no need to start asking a bunch of questions
about this in the Q and A section, all right?
So this will all make even more sense as we move on.
So I said that this string here is itself an expression.
And then this whole line of code is a statement,
because this again does not produce a value.
And so basically, whenever something ends with a semicolon,
that's then a statement.
It's like a complete sentence, okay?
Now this difference between expressions and statements
is important to know
because JavaScript expects
statements and expressions in different places.
For example, in a template literal,
we can only insert expressions, but not statements.
So let me just very quickly
demonstrate that to you.
So we can say, I am,
and then our placeholder here, basically.
And so in here, we need to put an expression.
So something that produces a value
which can then be put into the string
that we're building here using the template literal.
So let's say,
just to do some calculations here.
So 2037 minus 1991,
years old.
So again, this is an expression here.
And so this one will work.
However, we cannot do this.
For example, we could not insert
this if statement in here.
It wouldn't make any sense at all, okay?
Let's try that.
And so we actually get right away,
unexpected token, if.
And that's because JavaScript knows that this is a statement
and statements don't make sense
where JavaScript expects an expression.
Now, if we had a variable, for example,
then if we used that here,
then this would actually also be an expression.
Because this variable
will essentially just be replaced with this string.
And so this produces a value,
and so of course this is completely acceptable.
Okay, and that's actually all I had to show you
in this video.
Again, my goal was really just to make sure
that you kind of understand
the difference between expressions and declarations
so that moving forward,
we are really both on the same page here.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.