All language subtitles for 22. Statements and Expressions

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

Now that we're getting 2

2

more comfortable with JavaScript, 3

3

it's time to learn about a more theoretical concept. 4

4

And that's the difference 5

5

between statements and expressions. 6

6

And this is gonna be just a very high level overview, 7

7

just so that the future lecturers make more sense. 8

8

So essentially, an expression is a piece of code 9

9

that produces a value. 10

10

For example, three plus four is an expression 11

11

because this is gonna produce a value, okay? 12

12

So I don't even mean the entire line of code. 13

13

What I mean is really just this three plus four. 14

14

This is an expression, okay? 15

15

And again, because it does produce a value. 16

16

The same goes, for example for just any number. 17

17

This for example is an expression too, 18

18

even though it's just a simple value. 19

19

But it's still also an expression, 20

20

because again, this itself 21

21

will produce a value in JavaScript. 22

22

Or we can do this. 23

23

So true and false and, 24

24

not false. 25

25

So all of this here, 26

26

is an expression, right? 27

27

Because this will in the end, produce some Boolean value. 28

28

Now, on the other hand, we have statements. 29

29

And the statement is like a bigger piece of code 30

30

that is executed 31

31

and which does not produce a value on itself. 32

32

And we can compare this with normal spoken language. 33

33

And so in this example, 34

34

a declaration is like a complete sentence 35

35

and expressions are like the words 36

36

that make up the sentences. 37

37

Now, basically we write our whole programs 38

38

as a sequence of actions. 39

39

And these actions are statements. 40

40

So let's take as an example, the, if else, statement. 41

41

So let's say, 42

42

if 23 is greater than 10, 43

43

then, well just do something. 44

44

So create a string called, 23 is bigger. 45

45

The code itself doesn't really matter here. 46

46

So this, if else statement is in fact a statement. 47

47

And so that's the reason why I have called it 48

48

the if else statement all the time. 49

49

And the same is true for the switch statement. 50

50

So this statement here 51

51

doesn't really produce a value, does it? 52

52

All it does is, in this case, 53

53

it simply declares is variable called STR. 54

54

But that's it. 55

55

It performs some actions, 56

56

in this case, declaring this variable, 57

57

but it doesn't produce a value. 58

58

And so in that, it's different from, 59

59

for example, having this here, okay? 60

60

Now the string itself, again is an expression. 61

61

So this is probably a bit confusing, 62

62

but that's not a problem, okay? 63

63

My goal here is not that you understand 64

64

the exact rules of what an expression is 65

65

and what a statement is, 66

66

because, in fact, it's all a bit fuzzy. 67

67

So my main goal with this lecture is really 68

68

that you know that statements and expressions exist, 69

69

and that expressions produce values, 70

70

and that statements are like full sentences 71

71

that translate our actions. 72

72

So the actions that we want the program to perform, okay? 73

73

So really that's all you need to know, 74

74

and all you need to basically memorize from this video. 75

75

We don't need to go into all the details. 76

76

So there's no need to start asking a bunch of questions 77

77

about this in the Q and A section, all right? 78

78

So this will all make even more sense as we move on. 79

79

So I said that this string here is itself an expression. 80

80

And then this whole line of code is a statement, 81

81

because this again does not produce a value. 82

82

And so basically, whenever something ends with a semicolon, 83

83

that's then a statement. 84

84

It's like a complete sentence, okay? 85

85

Now this difference between expressions and statements 86

86

is important to know 87

87

because JavaScript expects 88

88

statements and expressions in different places. 89

89

For example, in a template literal, 90

90

we can only insert expressions, but not statements. 91

91

So let me just very quickly 92

92

demonstrate that to you. 93

93

So we can say, I am, 94

94

and then our placeholder here, basically. 95

95

And so in here, we need to put an expression. 96

96

So something that produces a value 97

97

which can then be put into the string 98

98

that we're building here using the template literal. 99

99

So let's say, 100

100

just to do some calculations here. 101

101

So 2037 minus 1991, 102

102

years old. 103

103

So again, this is an expression here. 104

104

And so this one will work. 105

105

However, we cannot do this. 106

106

For example, we could not insert 107

107

this if statement in here. 108

108

It wouldn't make any sense at all, okay? 109

109

Let's try that. 110

110

And so we actually get right away, 111

111

unexpected token, if. 112

112

And that's because JavaScript knows that this is a statement 113

113

and statements don't make sense 114

114

where JavaScript expects an expression. 115

115

Now, if we had a variable, for example, 116

116

then if we used that here, 117

117

then this would actually also be an expression. 118

118

Because this variable 119

119

will essentially just be replaced with this string. 120

120

And so this produces a value, 121

121

and so of course this is completely acceptable. 122

122

Okay, and that's actually all I had to show you 123

123

in this video. 124

124

Again, my goal was really just to make sure 125

125

that you kind of understand 126

126

the difference between expressions and declarations 127

127

so that moving forward, 128

128

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.